java Gradle:为所选子项目配置分发任务
我有一个多项目的渐变构建。我只想为其中两个子项目配置分发任务
假设我有一个根项目和子项目a、B&;C.我想为B&;配置分发任务;只有C
以下方法有效:
根目录项目/构建。格拉德尔
subprojects{
configure ([project(':B'), project(":C")]) {
apply plugin: 'java-library-distribution'
distributions {
main {
contents {
from('src/main/') {
include 'bin/*'
include 'conf/**'
}
}
}
}
}
但我对这样做很感兴趣
subprojects{
configure (subprojects.findAll {it.hasProperty('zipDistribution') && it.zipDistribution}) ) {
apply plugin: 'java-library-distribution'
distributions {
main {
contents {
from('src/main/') {
include 'bin/*'
include 'conf/**'
}
}
}
}
}
而且是内置的。B&;C、 我将有以下资料:
ext.zipDistribution = true
在后一种方法中,我有以下两个问题:
问题1
* What went wrong:
Task 'distZip' not found in root project 'root_project'.
* Try:
Run gradle tasks to get a list of available tasks.
问题2
我试图用以下代码验证是否可以在根_项目中读取属性zipDistribution
subprojects {
.....
// configure ([project(':B'), project(":C")]) {
apply plugin: 'java-library-distribution'
distributions {
/* Print if the property exists */
println it.hasProperty('zipDistribution')
main {
contents {
from('src/main/') {
include 'bin/*'
include 'conf/**'
}
}
}
}
// }
.....
}
上面的打印为空。hasProperty('zipDistribution')
有人能告诉我什么是正确的方法,让我看不到这些问题吗
# 1 楼答案
这是因为子项目是在根项目之后配置的。这就是为什么当时
ext.zipDistribution
是null
(它还没有被设置)您需要使用
afterEvaluate
来避免以下情况: