Skip to content

Commit

Permalink
do not handle transitives
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Jun 20, 2014
1 parent efe625c commit de4a89a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 116 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ v0.9.0-M4
+ `runShadow` now utilizes the output of the `shadowJar` and executes using `java -jar <shadow jar file>`
+ 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
=========
Expand Down
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -150,7 +150,7 @@ shadowJar {
}
```

Include specific dependencies (includes transitives by default)
Include specific dependency (transitive dependencies are **not** included)

```
shadowJar {
Expand All @@ -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

```
Expand All @@ -180,10 +170,6 @@ shadowJar {
}
```

Exclude a dependency and its transitives, except specified subset

**Not currently supported**

### Relocating dependencies

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? super ResolvedDependency> spec, boolean includeTransitive = true) {
public DependencyFilter exclude(Spec<? super ResolvedDependency> spec) {
Set<ResolvedDependency> 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))
}
Expand All @@ -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<? super ResolvedDependency> spec, boolean includeTransitive = true) {
Set<ResolvedDependency> 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))
}
Expand Down Expand Up @@ -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<ResolvedDependency> findMatchingDependencies(Closure spec,
Set<ResolvedDependency> dependencies,
boolean includeTransitive) {
Set<ResolvedDependency> dependencies) {
findMatchingDependencies(
Specs.<? super ResolvedDependency>convertClosureToSpec(spec), dependencies, includeTransitive)
Specs.<? super ResolvedDependency>convertClosureToSpec(spec), dependencies)
}

/**
* Support method for querying the resolved dependency graph using maven/project coordinates
* @param spec
* @param dependencies
* @param includeTransitive
* @return
*/
protected Set<ResolvedDependency> findMatchingDependencies(Spec<? super ResolvedDependency> spec,
Set<ResolvedDependency> dependencies,
boolean includeTransitive) {
Set<ResolvedDependency> dependencies) {

Set<ResolvedDependency> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -101,50 +101,14 @@ 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'])

and:
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')
Expand Down Expand Up @@ -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'() {
Expand Down Expand Up @@ -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'() {
Expand Down Expand Up @@ -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/%[email protected]%3E
def 'verify exclude precedence over include'() {
given:
Expand Down

0 comments on commit de4a89a

Please sign in to comment.