提问人:sdasa 提问时间:5/16/2023 更新时间:5/16/2023 访问量:140
如何在自定义 Gradle 任务下创建 JavaCompile 任务?
How to create a JavaCompile task under a Custom Gradle Task?
问:
我最近将我的 gradle 版本从 3.0 升级到了 5.6.4
我的一个 .groovy 文件中出现以下错误,它与 Gradle 3.0 配合良好
Could not find method execute() for arguments [] on task ‘:compileApp’ of type org.gradle.api.tasks.compile.JavaCompile
关于我正在尝试做的事情的简要介绍,我正在尝试创建和捆绑一个 .war 文件
**build.gradle**
tasks.create
( name: taskName,
type: Class.forName("com.org.xyz.implementation.groovy"),
overwrite: true) {
app thisApp
}
实现和捆绑在以下 implementation.groovy 文件中定义:
**implementation.groovy**
class implementation extends DefaultTask {
**@TaskAction**
def generate(){
#process 1
#process 2
// Here after process2, I would like to compile the processed .java files. So i'm creating a gradle task of type: JavaCompile with execute()
project.tasks.create (type: JavaCompile, name: 'compileSrcFIles') {
source <source dir>
destinationDir <destination>
classpath = project.sourceSets.main.compileClasspath
}.execute()
#process3
// Uses the compiled .class files from the above task and execution continues
}
}
现在,如果我删除.execute(),我会看到错误已解决,但是任务只是编译,没有执行任何操作。
我了解到 execute() 应该替换为 finalizedBy()、dependsOn 和 mustRunAfter(),但这在我的情况下没有任何意义。
如何在 implementation.groovy 的 @TaskAction() 块中调用 JavaCompile 任务?
使用的 Gradle 版本:5.6.4
答: 暂无答案
评论