Reputation: 5446
I have this in my gradle:
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
When I print the runtimeClasspath
in this code:
task runTopology(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
sourceSets.main.runtimeClasspath.each { println it }
I get something like:
...
/home/steven/.gradle/caches/modules-2/files-2.1/com.lmax/disruptor/3.3.2/8db3df28d7e4ad2526be59b54a1cbd9c9e982a7a/disruptor-3.3.2.jar
/home/steven/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.1/588c32c91544d80cc706447aa2b8037230114931/log4j-api-2.1.jar
/home/steven/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.1/31823dcde108f2ea4a5801d1acc77869d7696533/log4j-core-2.1.jar
/home/steven/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.1/fe9d0925aeee68b743e9ea4b68ca9190a2a411a/log4j-slf4j-impl-2.1.jar
/home/steven/.gradle/caches/modules-2/files-2.1/org.slf4j/log4j-over-slf4j/1.6.6/170e8f7395753ebbe6710bb862a84689db1f128b/log4j-over-slf4j-1.6.6.jar
...
Is it possible to exclude the line below in sourceSets.main.runtimeClasspath
?
/home/steven/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.1/fe9d0925aeee68b743e9ea4b68ca9190a2a411a/log4j-slf4j-impl-2.1.jar
I do not want to include it in the runtimeClasspath
as it crashes with another class in the classpath.
Upvotes: 2
Views: 1422
Reputation: 45432
You can use FileCollection.filter() to filter by file name.
The following will exclude log4j-slf4j-impl-2.1.jar
from runtimeClasspath
:
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
runtimeClasspath = runtimeClasspath.filter { File file ->
file.name ==~ "log4j-slf4j-impl-2.1.jar" ? null : file
}
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
runtimeClasspath = runtimeClasspath.filter { File file ->
file.name ==~ "log4j-slf4j-impl-2.1.jar" ? null : file
}
}
}
Upvotes: 3