From de4a89a52d7f4225ad92e435b94301b2bd50e9bf Mon Sep 17 00:00:00 2001 From: John Engelman Date: Fri, 20 Jun 2014 11:05:40 -0500 Subject: [PATCH] do not handle transitives --- ChangeLog.md | 2 + README.md | 18 +--- .../shadow/internal/DependencyFilter.groovy | 23 ++--- .../plugins/shadow/FilteringSpec.groovy | 89 ++----------------- 4 files changed, 16 insertions(+), 116 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1e2be1090..6be041b1f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,8 @@ v0.9.0-M4 + `runShadow` now utilizes the output of the `shadowJar` and executes using `java -jar ` + Start Scripts for shadow distribution now utilize `java -jar` to execute instead of placing all files on classpath and executing main class. ++ Excluding/Including dependencies no longer includes transitive dependencies. All dependencies for inclusion/exclusion + must be explicitly configured via a spec. v0.9.0-M3 ========= diff --git a/README.md b/README.md index 1c365dff7..755303fa9 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ shadowJar { ### Filtering shadow jar contents by maven/project dependency -Remove an external dependency and all of its transitive dependencies +Exclude specific dependency (transitive dependencies are **not** excluded) ``` shadowJar { @@ -150,7 +150,7 @@ shadowJar { } ``` -Include specific dependencies (includes transitives by default) +Include specific dependency (transitive dependencies are **not** included) ``` shadowJar { @@ -160,16 +160,6 @@ shadowJar { } ``` -Remove an external dependency but keep its transitive dependencies - -``` -shadowJar { - dependencies { - exclude(dependency('asm:asm:3.3.1'), false) - } -} -``` - Exclude a project dependency in a multi-project build ``` @@ -180,10 +170,6 @@ shadowJar { } ``` -Exclude a dependency and its transitives, except specified subset - -**Not currently supported** - ### Relocating dependencies ``` diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy index 90b6c05e3..91d359f3a 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter.groovy @@ -28,12 +28,11 @@ class DependencyFilter { * Exclude dependencies that match the provided spec. * * @param spec - * @param includeTransitive exclude the transitive dependencies of any dependency that matches the spec. * @return */ - public DependencyFilter exclude(Spec spec, boolean includeTransitive = true) { + public DependencyFilter exclude(Spec spec) { Set dependencies = findMatchingDependencies(spec, - project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies, includeTransitive) + project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies) dependencies.collect { it.moduleArtifacts.file }.flatten().each { File file -> this.mainSpec.exclude(FilenameUtils.getName(file.path)) } @@ -44,12 +43,11 @@ class DependencyFilter { * Include dependencies that match the provided spec. * * @param spec - * @param includeTransitive include the transitive dependencies of any dependency that matches the spec. * @return */ public DependencyFilter include(Spec spec, boolean includeTransitive = true) { Set dependencies = findMatchingDependencies(spec, - project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies, includeTransitive) + project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies) dependencies.collect { it.moduleArtifacts.file }.flatten().each { File file -> this.mainSpec.include(FilenameUtils.getName(file.path)) } @@ -110,36 +108,29 @@ class DependencyFilter { * Support method for querying the resolved dependency graph using maven/project coordinates * @param spec * @param dependencies - * @param includeTransitive * @return */ protected Set findMatchingDependencies(Closure spec, - Set dependencies, - boolean includeTransitive) { + Set dependencies) { findMatchingDependencies( - Specs.convertClosureToSpec(spec), dependencies, includeTransitive) + Specs.convertClosureToSpec(spec), dependencies) } /** * Support method for querying the resolved dependency graph using maven/project coordinates * @param spec * @param dependencies - * @param includeTransitive * @return */ protected Set findMatchingDependencies(Spec spec, - Set dependencies, - boolean includeTransitive) { + Set dependencies) { Set matched = [] dependencies.each { if (spec.isSatisfiedBy(it)) { matched.add(it) - if (includeTransitive) { - matched.addAll(findMatchingDependencies({true}, it.children, true)) - } } - matched.addAll(findMatchingDependencies(spec, it.children, includeTransitive)) + matched.addAll(findMatchingDependencies(spec, it.children)) } return matched } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy index 66742b6b9..95b121861 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy @@ -72,7 +72,7 @@ class FilteringSpec extends PluginSpecification { doesNotContain(output, ['a2.properties']) } - def "exclude dependency and its transitives"() { + def "exclude dependency"() { given: repo.module('shadow', 'c', '1.0') .insertFile('c.properties', 'c') @@ -101,42 +101,6 @@ class FilteringSpec extends PluginSpecification { then: success(result) - and: - contains(output, ['a.properties', 'a2.properties', 'b.properties']) - - and: - doesNotContain(output, ['c.properties', 'd.properties']) - } - - def "exclude dependency but retain transitives"() { - given: - repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() - repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() - - buildFile << ''' - |dependencies { - | compile 'shadow:d:1.0' - |} - | - |shadowJar { - | dependencies { - | exclude(dependency('shadow:d:1.0'), false) - | } - |} - '''.stripMargin() - - when: - runner.arguments << 'shadowJar' - ExecutionResult result = runner.run() - - then: - success(result) - and: contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties']) @@ -144,7 +108,7 @@ class FilteringSpec extends PluginSpecification { doesNotContain(output, ['d.properties']) } - def "include dependency and transitives, excluding all others"() { + def "include dependency, excluding all others"() { given: repo.module('shadow', 'c', '1.0') .insertFile('c.properties', 'c') @@ -179,10 +143,10 @@ class FilteringSpec extends PluginSpecification { success(result) and: - contains(output, ['c.properties', 'd.properties', 'shadow/Passed.class']) + contains(output, ['d.properties', 'shadow/Passed.class']) and: - doesNotContain(output, ['a.properties', 'a2.properties', 'b.properties']) + doesNotContain(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties']) } def 'filter project dependencies'() { @@ -236,11 +200,10 @@ class FilteringSpec extends PluginSpecification { and: doesNotContain(serverOutput, [ 'client/Client.class', - 'junit/framework/Test.class' ]) and: - contains(serverOutput, ['server/Server.class']) + contains(serverOutput, ['server/Server.class', 'junit/framework/Test.class']) } def 'exclude a transitive project dependency'() { @@ -304,48 +267,6 @@ class FilteringSpec extends PluginSpecification { 'server/Server.class']) } - @Ignore('need to figure out best way to do nested filtering') - def 'exclude a dependency but include one of its dependencies'() { - given: - repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() - repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .publish() - repo.module('shadow', 'e', '1.0') - .insertFile('e.properties', 'e') - .dependsOn('c', 'd') - .publish() - - buildFile << ''' - |dependencies { - | compile 'shadow:e:1.0' - |} - | - |shadowJar { - | dependencies { - | exclude(dependency('shadow:e:1.0')) { - | include(dependency('shadow:a:1.0')) - | } - | } - |} - '''.stripMargin() - - when: - runner.arguments << 'shadowJar' - ExecutionResult result = runner.run() - - then: - success(result) - - and: - contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties']) - - and: - doesNotContain(output, ['d.properties', 'e.properties']) - } - //http://mail-archives.apache.org/mod_mbox/ant-user/200506.mbox/%3C001d01c57756$6dc35da0$dc00a8c0@CTEGDOMAIN.COM%3E def 'verify exclude precedence over include'() { given: