def startBuildTime,endBuildTime this.afterEvaluate { Project project -> println "xxxxxx" def preBuildTask = project.tasks.getByName('compileJava') preBuildTask.doFirst { startBuildTime = System.currentTimeMillis() println("ccccccccccccccc") println 'ths start time is:'+startBuildTime } def buildTask = project.tasks.getByName('build') buildTask.doLast { endBuildTime = System.currentTimeMillis() println "eeeeeeee" // println "the build time is:${endBuildTime - startBuildTime}" } println "zzzzzz" }
为什么我这个例子,doFirst不执行?
输出结果:
D:\source\demo\gradleTest4>gradle build
xxxxxx
zzzzzz
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
eeeeeeee
BUILD SUCCESSFUL