0
我有一个多项目Gradle构建,具有自定义的定义xjc任务来构建jaxb生成的对象,并且我正在按照正确的顺序构建步骤。Gradle中的自定义任务构建顺序
我有3个项目,通用,参考和产品。参考取决于共同和产品取决于参考和共同。命名对于我的问题很重要,因为它看起来像gradle按字母顺序执行某些操作,并且我已经剥离了一些其他依赖项,因为它们不会影响问题。
在每个项目中,顺序应该是jaxb,java编译,然后scala编译。
在顶层的build.gradle我指定的JAXB任务是:
task jaxb() {
description 'Converts xsds to classes'
def jaxbTargetFile = file(generatedSources)
def jaxbSourceFile = file (jaxbSourceDir)
def jaxbEpisodesFile = file (jaxbEpisodeDir)
def bindingRootDir = file (rootDir.getPath() + '/')
inputs.dir jaxbSourceDir
outputs.dir jaxbTargetFile
doLast {
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxb.asPath)
jaxbTargetFile.mkdirs()
jaxbEpisodesFile.mkdirs()
for (xsd in bindingsMap) {
if (!episodeMap.containsKey(xsd.key)) {
ant.fail("Entry no found in the episodeMap for xsd $xsd.key")
}
def episodeFile = projectDir.getPath() + '/' + jaxbEpisodeDir + '/' + episodeMap.get(xsd.key)
println("Processing xsd $xsd.key with binding $xsd.value producing $episodeFile")
ant.xjc(destdir: "$jaxbTargetFile", extension: true, removeOldOutput: true) {
schema(dir:"$jaxbSourceFile", includes: "$xsd.key")
binding(dir:"$bindingRootDir" , includes: "$xsd.value")
arg(value: '-npa')
arg(value: '-verbose')
arg(value: '-episode')
arg(value: episodeFile)
}
}
}
}
在产品个体的build.gradle文件我指定(在参考类似)
dependencies {
compile project(':common')
compile project(':ref')
}
并在我指定的所有三个项目中,我指定
compileJava.dependsOn(jaxb)
当我在产品项目中运行发布(或jar)时,我可以看到下面的输出:
common:jaxb
common:compileJava
common:compileScala
common:jar
product:jaxb
ref:jaxb
refcompileJava
ref:compileScala
ref:jar
product:compileJava
product:compileScala
这给了我一个错误,因为在产品的XSD指裁判和裁判还没有运行JAXB还没有发作约束力文件ref和产品再生进口类与错包裹名字。
如何确保ref jaxb在产品jaxb之前运行?
是的,这工作,谢谢。我希望找到一个更通用的方法,使用已经设置的依赖关系,但这确实解决了这个问题。 – Klunk
你也可以试试这个:'任务jaxb(dependsOn:configurations.compile)' –