Question

I have a multi-project Gradle build with a custom defind xjc task to build the jaxb generated objects and I am having issues with steps building in the correct order.

I have 3 projects, common, ref and product. ref depends on common and product depends on ref and common. The naming is important to my problem as it seems gradle does things in alphabetical order and I have stripped out some other dependencies as they do not impact the problem.

Within each project the order should be jaxb, java compile and then scala compile.

In the top level build.gradle I specify the jaxb task to be:

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)
            }
        }
    }
}

In the individual build.gradle file for product I specify (with similar in ref)

dependencies {
     compile project(':common')
     compile project(':ref')
}

and in all three projects I specify

compileJava.dependsOn(jaxb)

when I run publish (or jar) in the product project I can see the following output:

common:jaxb
common:compileJava
common:compileScala
common:jar
product:jaxb
ref:jaxb
refcompileJava
ref:compileScala
ref:jar
product:compileJava
product:compileScala

This gives me an error because the xsd in product refers to ref and as ref has not run jaxb yet there are no episode binding files for ref and product regenerates the imported classes with the wrong package name.

How can I ensure that ref jaxb runs before product jaxb?

Était-ce utile?

La solution

If your product's jaxb tasks depends on jaxb tasks for ref and common, you should define this dependency:

(in product build.gradle)

task jaxb(dependsOn: [':common:jaxb', ':ref:jaxb']) {
...
}

Set same kind dependency in ref (on commmon)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top