2016-09-15 74 views

回答

1

是的,你可以。你有幾個選擇。您可以隨時與生命週期掛鉤。默認情況下,java gradle插件有幾個地方可以掛鉤。

$ ./gradlew clean build 
:clean 
:compileJava 
:processResources UP-TO-DATE 
:classes 
:jar 
:assemble 
:compileTestJava 
:processTestResources UP-TO-DATE 
:testClasses 
:test 
:check 
:build 

,如果你需要,不管別的,然後之前,你可能要考慮一個簡單的插件什麼應用可以連接到任何這些點

或者你的。

這裏既是一個例子:

的build.gradle:

apply plugin: 'java' 

repositories { 
    jcenter() 
} 

dependencies { 
    testCompile 'junit:junit:4.12' 
} 

task runFlyAwayCommand << { 
    // process is type java.lang.Process 
    def process = "printf lifecycle hooked task".execute() 
    def processExitValue = process.waitFor() 
    def processOutput = process.text 
    project.logger.lifecycle("Flyaway{ exitValue: $processExitValue output: $processOutput }") 
} 

// compileJava could be any lifecycle task 
tasks.findByName('compileJava').dependsOn tasks.findByName('runFlyAwayCommand') 


// if you need to execute earlier you might want to create a plugin 
apply plugin: SamplePlugin 

class SamplePlugin implements Plugin<Project> { 

    @Override 
    void apply(Project project) { 
     def process = "printf plugin apply".execute() 
     def processExitValue = process.waitFor() 
     def processOutput = process.text 
     project.logger.lifecycle("Flyaway{ exitValue: $processExitValue output: $processOutput }") 
    } 
} 

輸出:

$ ./gradlew clean build 
Configuration on demand is an incubating feature. 
Flyaway{ exitValue: 1 output: plugin } 
:clean 
:runFlyAwayCommand 
Flyaway{ exitValue: 1 output: lifecycle } 
:compileJava 
:processResources UP-TO-DATE 
:classes 
:jar 
:assemble 
:compileTestJava 
:processTestResources UP-TO-DATE 
:testClasses 
:test 
:check 
:build 

BUILD SUCCESSFUL 

Total time: 1.294 secs 
+0

感謝您的周到的答案,我給一個去。 – ben3000

相關問題