根据父项目的任务,Gradle子项目任务的语法是什么? [英] What is the syntax for a gradle subproject task depending on a parent project's task?
问题描述
我需要一些Gradle构建文件的帮助。我有一些依赖顶层文件夹任务的子项目。我只需要执行 test
任务并将其分成两个独立的测试任务。目前文件系统结构看起来像(选项卡表示目录中的文件):
I need some help with a Gradle build file. I have some subprojects which depend on tasks in the top folder. I just need to take a test
task and split it into two separate test tasks. Currently the file system structure looks like (tab indicates files inside a directory):
top-level-project-folder
A.gradle
B.gradle
C-subproject-folder
C.gradle
D-subproject-folder
D.gradle
A.gradle的内容(重构之前):
Contents of A.gradle (before refactor):
subprojects {
tasks.test.dependsOn {
bTask
}
}
apply from: 'B.gradle'
C.gradle的内容(重构之前):
Contents of C.gradle (before refactor):
test {
...
}
重构后,C.gradle需要如下所示:
After the refactor, C.gradle needs to look like:
test {
...
}
task runDifferentTests(type : Test) {
...
}
棘手的部分是 test
任务目前依赖于 bTask
。但是,在重构之后, C.gradle
的 test
任务应该 not 取决于 bTask
,但是新的 runDifferentTests
任务应该依赖于 bTask
。 (目前, D.gradle
的 test
任务被标记为取决于 bTask
,但实际上并不依赖于它 - 我想删除这个依赖关系。依赖于
bTask
的两个子项目中唯一的任务是新的 runDifferentTests
任务。)
The tricky part is that C.gradle
's test
task currently depends on bTask
. However, after the refactor, C.gradle
's test
task should not depend on bTask
, but the new runDifferentTests
task should depend on bTask
. (Currently, D.gradle
's test
task is marked as depending on bTask
, but it does not actually depend on it -- I'd like to remove that dependency. The only task in the two subprojects which depends on bTask
is the new runDifferentTests
task.)
我尝试了一些不同的东西,但似乎无法找到工作解决方案。
I've tried some different things but can't seem to find a working solution.
推荐答案
只要删除子项目
中的声明并声明您的依赖项直接在子项目中的 C.gradle
:
Just remove the declaration in subprojects
and declare your dependency directly in the subproject, in C.gradle
:
runDifferentTests.dependsOn rootProject.bTask
这篇关于根据父项目的任务,Gradle子项目任务的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!