Skip to content

Commit

Permalink
Allow regex filtering in dependencies. closes #83
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Nov 14, 2014
1 parent 4ebff18 commit e1b3fa8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Expand Up @@ -5,6 +5,7 @@ v1.2.0
+ Upgrade JDOM library from 1.1 to 2.0.5 (change dependency from `jdom:jdom:1.1` to `org.jdom:jdom2:2.0.5`) ([Issue #98](https://github.com/johnrengelman/shadow/issues/98))
+ Convert ShadowJar.groovy to ShadowJar.java to workaround binary incompatibility introduced by Gradle 2.2 ([Issue #106](https://github.com/johnrengelman/shadow/issues/106))
+ Updated ASM library to `5.0.3` to support JDK8 ([Issue #97](https://github.com/johnrengelman/shadow/issues/97))
+ Allows for regex pattern matching in the `dependency` string when including/excluding ([Issue #83](https://github.com/johnrengelman/shadow/issues/83))

v1.1.2
======
Expand Down
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -225,6 +225,28 @@ shadowJar {
}
```

Include or exclude dependencies using regex pattern matching. The string is split on the `:` character in the form
`<group>:<name>:<version>`. Each piece is compared as a regex to the values of the resolved dependencies.

```
shadowJar {
dependencies {
include(dependency('asm:asm:.*'))
}
}
```

If a piece of the string is not specified, then that field is not used for the matching. Thus the following syntax
results in the same filtering as the example above.

```
shadowJar {
dependencies {
include(dependency('asm:asm'))
}
}
```

Exclude a project dependency in a multi-project build.

```
Expand Down
Expand Up @@ -94,9 +94,9 @@ class DefaultDependencyFilter implements DependencyFilter {
*/
Spec<? super ResolvedDependency> dependency(Dependency dependency) {
this.dependency({ ResolvedDependency it ->
(!dependency.group || dependency.group == it.moduleGroup) &&
(!dependency.name || dependency.name == it.moduleName) &&
(!dependency.version || dependency.version == it.moduleVersion)
(!dependency.group || it.moduleGroup.matches(dependency.group)) &&
(!dependency.name || it.moduleName.matches(dependency.name)) &&
(!dependency.version || it.moduleVersion.matches(dependency.version))
})
}

Expand Down
Expand Up @@ -104,6 +104,43 @@ class FilteringSpec extends PluginSpecification {
doesNotContain(output, ['d.properties'])
}

@Issue('SHADOW-83')
def "exclude dependency using wildcard syntax"() {
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:.*'))
| }
|}
'''.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'])
}

@Issue("SHADOW-54")
def "dependency exclusions affect UP-TO-DATE check"() {
given:
Expand Down

0 comments on commit e1b3fa8

Please sign in to comment.