title: Custom task build order in Gradle
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Within each project the order should be jaxb, java compile and then scala compile.</p>
  
  <p>In the top level build.gradle I specify the jaxb task to be:</p>
  
  <pre><code>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)
              }
          }
      }
  }
  </code></pre>
  
  <p>In the individual build.gradle file for product I specify (with similar in ref) </p>
  
  <pre><code>dependencies {
       compile project(':common')
       compile project(':ref')
  }
  </code></pre>
  
  <p>and in all three projects I specify</p>
  
  <pre><code>compileJava.dependsOn(jaxb)
  </code></pre>
  
  <p>when I run publish (or jar) in the product project I can see the following output:</p>
  
  <pre><code>common:jaxb
  common:compileJava
  common:compileScala
  common:jar
  product:jaxb
  ref:jaxb
  refcompileJava
  ref:compileScala
  ref:jar
  product:compileJava
  product:compileScala
  </code></pre>
  
  <p>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.</p>
  
  <p>How can I ensure that ref jaxb runs before product jaxb?</p>