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
。