2014-02-26 221 views
8

我將對此失去主意。我有一個build.gradle文件看起來是這樣的:將任務依賴關係添加到現有的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 ... 

我無法找出正確的語法是什麼。任何幫助?

回答

23

這應該工作:

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

的原因是觀念插件創建組織。項目中的gradle.plugins.ide.idea.model.IdeaModel。參考'idea'就像'project.idea',它在任務之前查找模型。 – Alpar

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' 
相關問題