不完全确定你追求的是哪一个,但它们应该涵盖你的基地。
1.直接调用任务
你应该可以打电话
gradle :other/projC:hello :other/projD:hello
我对此进行了测试:
# Root/build.gradle
allprojects {
task hello << { task -> println "$task.project.name" }
}
和
# Root/settings.gradle
include 'projA'
include 'projB'
include 'other/projC'
include 'other/projD'
2。仅在子项目中创建任务
还是您只希望在其他/* 项目上创建任务?
如果是后者,那么以下工作:
# Root/build.gradle
allprojects {
if (project.name.startsWith("other/")) {
task hello << { task -> println "$task.project.name" }
}
}
然后可以调用它:
$ gradle hello
:other/projC:hello
other/projC
:other/projD:hello
other/projD
3.创建仅在子项目中运行任务的任务
此版本与我对您问题的阅读相匹配,这意味着子项目 (buildJar) 上已经有一个任务,并在根目录中创建一个只会调用子项目 other/*:buildJar 的任务
allprojects {
task buildJar << { task -> println "$task.project.name" }
if (project.name.startsWith("other/")) {
task runBuildJar(dependsOn: buildJar) {}
}
}
这会在每个项目上创建一个任务“buildJar”,并仅在其他/*项目上创建一个“runBuildJar”,因此您可以调用:
$ gradle runBuildJar
:other/projC:buildJar
other/projC
:other/projC:runBuildJar
:other/projD:buildJar
other/projD
:other/projD:runBuildJar
您的问题可以通过多种方式阅读,希望这涵盖了所有内容:)