我认为这样可行,但事情必定已经改变(或者我有某种错误)
What is the syntax for a gradle subproject task depending on a parent project's task?
我在根级别有以下任务(即在子项目闭包之外和allprojects闭包之外)。
task deleteJavaCache {
doLast {
System.out.println("DELETE java caches here to prevent intermitten build failures from java deleting files")
}
}
test.dependsOn rootProject.deleteJavaCache
test{
beforeTest{ descr ->
logger.warn("Starting Test ${descr.className} : ${descr.name}")
}
...
我得到的错误是
A problem occurred evaluating root project 'webpieces'.
> Could not get unknown property 'deleteJavaCache' for root project
'webpieces' of type org.gradle.api.Project.
然后我猜到了一些事情,包括这个
test.dependsOn rootProject.task('deleteJavaCache')
但这给了我错误
* What went wrong:
A problem occurred evaluating root project 'webpieces'.
> Cannot add task ':deleteJavaCache' as a task with that name already exists.
版本信息因此
------------------------------------------------------------
Gradle 4.1-milestone-1
------------------------------------------------------------
Build time: 2017-06-20 17:05:46 UTC
Revision: 3ad5af92d482b963cc6b00fb5ad53b608606d657
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_111 (Oracle Corporation 25.111-b14)
OS: Mac OS X 10.11.6 x86_64
答案 0 :(得分:2)
仔细检查您的settings.gradle
以及子项目是否为include
如果我理解的话,就是这样:
root (deleteJavaCache)
|- subprojects (test.dependsOn deleteJavaCache from the root)
试试这个:
test.dependsOn (":deleteJavaCache")
或者如果您希望所有子项目test
任务之前运行它:
//in root build.gradle
subprojects {
test.dependsOn (":deleteJavaCache")
}
因为我认为您正在尝试自定义子项目test
任务以使其依赖于根项目的任务?
因为你说的有点混乱:
我在根级别有以下任务
这意味着整个代码块都在根项目中,包括deleteJavaCache
和test
任务。如果是,请尝试以下解决方案,如果没有,上面的解决方案请澄清问题。
test.dependsOn deleteJavaCache