将任务相关性添加到现有 Gradle 任务

2022-09-03 00:02:45

我会对此失去理智。我有一个文件,看起来像这样:build.gradle

apply plugin: 'idea'
task blah{
  // do something
}
idea{
  // some stuff
  dependsOn blah
}

我得到这个:

Could not find method dependsOn() for arguments [task ':blah'] on root project ...

我不知道什么是正确的语法。有什么帮助吗?


答案 1

这应该有效:

apply plugin: 'idea'
task blah{
  // do something
}
tasks.idea.dependsOn(blah)

答案 2

也许我的工作示例会很有用 - build.gradle的片段:(gradle版本的1.6)

ear {

    doFirst {
        tasks.buildWar.execute();
    }

    ...

}

task deployProj <<{
    tasks.ear.execute()
    tasks.copyEar.execute()
    tasks.copyJar.execute()
}

task buildWar(type: GradleBuild) {
    buildFile = 'mysubproject/build.gradle'
    tasks = ['war']
}

task copyEar(type: Copy) {
    from earPath
    into "$System.env.JBOSS_HOME" + deploymentPath
}

task copyJar(type: Copy) {
    from jarPath
    into libPath
}

copyEar.mustRunAfter 'ear'
copyJar.mustRunAfter 'ear'

推荐