Java 在自定义任务的根项目gradle上找不到属性

Java 在自定义任务的根项目gradle上找不到属性,java,build,gradle,build.gradle,Java,Build,Gradle,Build.gradle,我编写了一个自定义任务copyDocs,将生成输出复制到其他目录,并在dependsOn中给出了此任务,如下所示: task doit(dependsOn: ['clean', 'build', 'copyDocs']) build.mustRunAfter clean copyDocs.mustRunAfter build .... .... task copyDocs(type: Copy) { from 'build/libs' into 'build' } 上面是

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

task doit(dependsOn: ['clean', 'build', 'copyDocs'])
build.mustRunAfter clean
copyDocs.mustRunAfter build
....
....
task copyDocs(type: Copy) {
     from 'build/libs'
     into 'build'
 }
上面是自定义任务
doit
,它必须按照使用
mustRunAfter
定义的顺序执行
clean
build
copyDocs
。但在执行过程中会出现错误

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.mustRunAfter
时没有定义名为
copyDocs
的任务。
您应该将
copyDocs
任务定义放在
copyDocs.mustRunAfter build
语句之前。

在编写
copyDocs.mustRunAfter build
之前,请尝试定义
task copyDocs