我编写了一个自定义任务copyDocs,将构建输出复制到其他目录,并在dependsOn中给出了此任务,如下所示:

task doit(dependsOn: ['clean', 'build', 'copyDocs'])
build.mustRunAfter clean
copyDocs.mustRunAfter build
....
....
task copyDocs(type: Copy) {
     from 'build/libs'
     into 'build'
 }

上面是定制任务doit,必须按使用clean定义的顺序执行buildcopyDocsmustRunAfter。但是在执行过程中会给出错误。
During execution (i.e. cmd>gradle doit), I am getting the following error:

* What went wrong:
A problem occurred evaluating script.
> Could not find property 'copyDocs' on root project 'gradle'.
BUILD FAILED

请帮助解决此问题。

最佳答案

您会收到此错误,因为执行copyDocs时没有定义的任务称为copyDocs.mustRunAfter
您应该将copyDocs任务定义放在copyDocs.mustRunAfter build语句之前。

10-07 16:58