gpt4 book ai didi

gradle - 让所有 gradle 子项目 'test' 任务依赖于 rootproject 'setup' 任务

转载 作者:行者123 更新时间:2023-12-03 03:12:51 31 4
gpt4 key购买 nike

我认为这会起作用,但事情一定已经改变了(或者我有某种错误)

What is the syntax for a gradle subproject task depending on a parent project's task?

我在根级别有以下任务(即在 subprojects 关闭之外和 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

最佳答案

仔细检查您的 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任务使其依赖于根项目的任务?

因为您说的有点令人困惑:

I have the following task at the root level



这意味着整个代码块都在根项目中, deleteJavaCachetest任务。如果是,请尝试以下解决方案,如果不是,请尝试上述解决方案,请澄清问题。
test.dependsOn deleteJavaCache

关于gradle - 让所有 gradle 子项目 'test' 任务依赖于 rootproject 'setup' 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44873848/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com