简体   繁体   中英

Gradle : Task dependency tree ignored?

I have a problem with gradle's task dependencies.

I have a version.properties file which must be cleared (on clean task) or filled (on war task) with a version info.

Therefore I set this dependency :

clean.dependsOn clearVersionProperties

and

processResources.dependsOn ([defaultValues,infoEnv])
compileJsps.dependsOn(classes, tomcatJasper, xmlModify)
war.dependsOn(compileJsps, svnRevision, writeVersionProperties)

My tasks have been externalized in a commons.gradle and look like this:

...

def writeVersionFile(String whatToWrite) {
    File f = new File(project.webAppDirName+'/WEB-INF/version.properties');
    if (f.exists()) { f.delete(); }

    f = new File(project.webAppDirName+'/WEB-INF/version.properties');
    FileOutputStream os = new FileOutputStream(f);
    os.write(whatToWrite.getBytes());
    os.flush();
    os.close();
}

task clearVersionProperties() {
    println "Clearing version file"
    String whatToWrite = "version=@version@"
    writeVersionFile(whatToWrite)
}

task writeVersionProperties(dependsOn: svnRevision) {
    println "Writing version file"
    String whatToWrite = "version="+project.ext.revision;
    writeVersionFile(whatToWrite)
}
...

From my understanding clean will now call clearVersionProperties and war will call writeVersionProperties.

But when I execute a gradle clean, the reactor plan looks like this :

C:\devtools\....\branches\merge\Application>gradle -bbuild20.gradle clean -Ptomcat=7 -Ptarget=live

To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: http://gradle.org/
docs/2.0/userguide/gradle_daemon.html.
_______________________________________________________________________________

### building LIVE system

_______________________________________________________________________________
Clearing version file
Writing version file
JSP compilation...
TC7 Sources integrated
________________________________________________________
Compiling JSPs against Tomcat 7.0.11
________________________________________________________
:clearVersionProperties UP-TO-DATE
:clean UP-TO-DATE

BUILD SUCCESSFUL

Total time: 16.803 secs

Why are the tasks clearVersionProperties and writeVersionProperties executed, since they are bound to certain build phases? for example the task infoEnv is not executed, but - and this is really a problem - the task writeVersionProperties which only should be executed by the war task.

Any help appreciated!

in the meantime I found out why these tasks were fired :

I missed << after the task statement, so changing my two taks to

task clearVersionProperties() << {
    println "Clearing version file"
    String whatToWrite = "version=@version@"
    writeVersionFile(whatToWrite)
}

task writeVersionProperties(dependsOn: [svnRevision]) << {
    println "Writing version file"
    String whatToWrite = "version="+project.ext.revision;
    writeVersionFile(whatToWrite)
}

writeVersionProperties.mustRunAfter clearVersionProperties

This did the job.... I am not sure, if this is a bug, feature or side effect. But it seems to me the same utterly evil trap like forgetting () after a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM