【发布时间】:2018-10-29 17:50:09
【问题描述】:
gradle 的另一个奇怪行为...
所以我找到了这篇文章: Gradle exclude module for Copy task
完全没问题,就像一种魅力,可以将某些东西排除在复制之外。
但这就是有趣的地方。这是我的复制任务的外观:
task copyDependencies(type: Copy) {
into "$buildDir/libs/dependencies"
from configurations.runtime {
exclude module: 'groovy'
exclude module: 'aws-java-sdk-s3'
exclude module: 'commons-io'
}
}
如果我尝试通过 Gradles 的“应用程序运行”任务运行应用程序。 “无法找到或加载主类 xxx” 失败。深入研究这个问题,我发现 Groovy 无法解决。
我什至不运行这个任务,或者依赖它。 但如果我这样注释掉第 4 行:
task copyDependencies(type: Copy) {
into "$buildDir/libs/dependencies"
from configurations.runtime {
//exclude module: 'groovy'
exclude module: 'aws-java-sdk-s3'
exclude module: 'commons-io'
}
}
应用程序正常启动,直到达到需要 Commons-IO 的程度。我仍然想在其他时候使用这个 copyDependencies 任务,但不改变那里的代码。
有人可以解释一下这种行为吗?
我想在 gradle 文件中的任何位置操作 configuration.runtime,为其他所有任务更改它?
【问题讨论】:
-
我试图在我的回答中解释这种行为,如果足够清楚,请告诉我。
-
接受了。它奏效了,尽管我现在使用另一种方式将应用程序与其依赖项分开。仍然很高兴知道这些似乎是静态声明并在各个任务之间共享。