gradle'build'任务混乱 [英] gradle 'build' task confusion
问题描述
您好我有多个项目gradle设置
-root_project
| -sub_project1
| -sub_project2
| -sub_project3
所有的工作都很棒,但有一件事令我发狂。在我的构建脚本中:
defaultTasks'build'< - 这可以正常工作
任务buildroom (描述:'这个任务被build room脚本调用,调用默认任务加发布工件'){
// dependsOn('build')< - 这不起作用
//替代
dependsOn(:sub_project1:build)
dependsOn(:sub_project2:build)
当我从命令行'gradlew'调用< - 默认任务执行时
当我从命令行调用'gradlew tasks' < - 任务在'从root项目运行的所有任务'下我看到'build'
但是当我尝试添加dependsOn('build'),dependsOn(' build')或dependsOn(':root:build')它告诉我:
出错了:任务执行失败':tasks' 。
无法确定任务':buildroom'的依赖关系。
'base'插件添加'assemble'和'clean'任务,但不会构建...
任何提示?
build
任务由 java-base code>插件。很可能您的根项目不会(直接或间接)应用 java-base
,因此没有构建
任务。这就是为什么 dependsOn(build)
,它会在 build
的任务依赖关系>同一个项目,最终会导致错误。 defaultTasks
不同之处在于: - 它只接受任务名称(而
dependsOn
也接受任务路径和任务
对象)。 - 其任务名称已解析为任务,就好像任务名称已在命令行中输入一样。换句话说,所有项目都会搜索具有给定名称的任务,并返回一组匹配的任务。
Hi I have multi project gradle setup
-root_project
|-sub_project1
|-sub_project2
|-sub_project3
All works great but one thing drives me crazy. In my build script:
defaultTasks 'build' <- this works just fine
task buildroom (description: 'This task is invoked by build room script, invokes default task plus publishes artifacts') {
// dependsOn('build') <-- this doesn't work
// alternative
dependsOn(":sub_project1:build")
dependsOn(":sub_project2:build")
when i call from command line 'gradlew' <- default task gets executed
when i call from command line 'gradlew tasks' <- task under 'all task runnable from root project' i see 'build'
but when i try to add dependsOn('build'), dependsOn(':build') or dependsOn(':root:build') it tells me
What went wrong: Execution failed for task ':tasks'.
Could not determine the dependencies of task ':buildroom'.
'base' plugin adds 'assemble', and 'clean' task but not build...
any tips?
The build
task is declared by the java-base
plugin. It's likely that your root project doesn't (directly or indirectly) apply java-base
and therefore doesn't have a build
task. This is why dependsOn("build")
, which adds a task dependency on a task named build
in the same project, eventually causes an error. defaultTasks
is different in that:
- It only accepts task names (whereas
dependsOn
also accepts task paths andTask
objects). - Its task names get resolved to tasks as if the task names had been entered on the command line. In other words, all projects are searched for a task with the given name, and the set of matching tasks is returned.
这篇关于gradle'build'任务混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!