gpt4 book ai didi

java - 删除 sourceSets.main.runtimeClasspath 中的 jar

转载 作者:行者123 更新时间:2023-11-30 06:47:11 25 4
gpt4 key购买 nike

我的 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 中,因为它会与类路径中的另一个类一起崩溃。

最佳答案

您可以使用FileCollection.filter()按文件名过滤。
以下将从 runtimeClasspath 中排除 log4j-slf4j-impl-2.1.jar :

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
}
}
}

关于java - 删除 sourceSets.main.runtimeClasspath 中的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43512061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com