我想在 Gradle 文件中获取任务的依赖项列表,以便向onlyIf
它们添加子句(这样可以关闭任务依赖项的分支——与在 Gradle 中跳过禁用任务的依赖项执行有关?) . 如何才能做到这一点?
例如:
def shouldPublish = {
def propertyName = 'publish.dryrun'
!project.hasProperty(propertyName) || project[propertyName] != 'true'
}
subprojects {
publish {
onlyIf shouldPublish
// the following doesn't work;the gist is that publish's dependencies should be turned off, too
dependencies {
onlyIf shouldPublish
}
}
}
然后,在命令行上,可以:
gradlew -Ppublish.dryrun=true publish