我遇到了gradle的任务依赖问题。
我有一个version.properties文件,必须使用版本信息清除(在清洁任务上)或填充(在war任务中)。
因此我设置了这种依赖:
clean.dependsOn clearVersionProperties
和
processResources.dependsOn ([defaultValues,infoEnv])
compileJsps.dependsOn(classes, tomcatJasper, xmlModify)
war.dependsOn(compileJsps, svnRevision, writeVersionProperties)
我的任务已在commons.gradle中外部化,如下所示:
...
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)
}
...
根据我的理解,clean现在将调用clearVersionProperties,war将调用writeVersionProperties。
但是当我执行gradle clean时,反应堆计划看起来像这样:
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
为什么执行任务clearVersionProperties和writeVersionProperties,因为它们绑定到某些构建阶段?例如,任务infoEnv没有被执行,但是 - 这确实是一个问题 - 任务writeVersionProperties只应该由war任务执行。
任何帮助表示赞赏!
答案 0 :(得分:0)
与此同时,我发现了为什么这些任务被解雇了:
我错过了<<在任务声明之后,所以将我的两个改变为
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
这完成了工作....我不确定,如果这是一个错误,功能或副作用。但在我看来,在一个函数之后就像遗忘()一样完全是邪恶的陷阱。