我的 gradle 中有这个:
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
当我打印runtimeClasspath
在这段代码中:
task runTopology(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
sourceSets.main.runtimeClasspath.each { println it }
我得到类似的东西:
...
/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
...
是否可以排除下面的行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
我不想将其包含在runtimeClasspath
因为它与类路径中的另一个类崩溃。
您可以使用文件集合.filter() https://docs.gradle.org/3.0/javadoc/org/gradle/api/file/FileCollection.html按文件名过滤。
以下将排除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
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)