[英]Gradle : Task dependency tree ignored?
I have a problem with gradle's task dependencies. 我对gradle的任务依赖项有疑问。
I have a version.properties file which must be cleared (on clean task) or filled (on war task) with a version info. 我有一个version.properties文件,必须将其清除(在执行清理任务时)或在版本中(执行战争任务时)填充版本信息。
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: 我的任务已在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)
}
...
From my understanding clean will now call clearVersionProperties and war will call writeVersionProperties. 根据我的理解,clean现在将调用clearVersionProperties,而war将调用writeVersionProperties。
But when I execute a gradle clean, the reactor plan looks like this : 但是当我执行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
Why are the tasks clearVersionProperties and writeVersionProperties executed, since they are bound to certain build phases? 由于将任务clearVersionProperties和writeVersionProperties绑定到某些构建阶段,为什么还要执行这些任务? 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.
例如任务infoEnv没有执行,但是-这的确是个问题-任务writeVersionProperties仅应由war任务执行。
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.
但是在我看来,这完全是一个邪恶的陷阱,就像在函数之后忘记()一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.