在配置阶段不执行Gradle任务(类型:Exec)

时间:2017-02-05 18:28:20

标签: gradle

我正在阅读Gradle build lifecycle

这是我的剧本:

task startTomcat(type:Exec) {
    commandLine 'cmd', '/c', 'echo init startTomcat'
} 

task stopTomcat(type:Exec) {

    // on windows:
    commandLine 'cmd', '/c', 'echo init stopTomcat!'
    doLast {
        commandLine 'cmd', '/c', 'echo doLast stopTomcat!'
    }
}


task configured(type:Exec) {
    println 'configured. method body'
}

task test2 {
    doLast {
        println 'test2 doLast'
    }
}

task testBoth2 {
    doFirst {
      println 'testBoth2 doFirst'
    }
    doLast {
      println 'testBoth2 doLast'
    }
    println 'testBoth2. method body'
}

我运行task2:

gradlew test2

这是输出:

Parallel execution with configuration on demand is an incubating feature.
configured. method body
testBoth2. method body
:test2
test2 doLast

BUILD SUCCESSFUL

看起来对commandLine的调用被忽略了。为什么呢?

1 个答案:

答案 0 :(得分:3)

Exec taskcommandLine只能正确配置执行任务时的操作。因此,您不会在配置阶段看到实际命令执行任何操作。