Need help with inputs/outputs for doing incremental build with xjc


(william.r.phillips.jr) #1

In my gradle build, I need to use XJC to create stub classes from an xsd file.

I have created the following tasks:

task antdef(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME) {
 project.ext.rootDir = file('/src/main/java')
    doLast {
  ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.xjcbeans.asPath) {
  }
 }
}
  task xjcItemThing(dependsOn: antdef) {
 ext.itemThingDir = new File(project.ext.rootDir, '/com/foo/product/beans/itemThing')
 ext.itemThingXsd = new File(itemThingDir, 'itemThingFile.xsd')
 ext.itemThingXjb = new File(itemThingDir, 'itemThingFile.xjb')
    // incremental inputs/outputs
 inputs.files(itemThingXsd, itemThingXjb)
 outputs.dir itemThingDir
    doLast {
  ant.xjc(destdir: project.ext.rootDir, extension: 'true', header: 'false', removeOldOutput: 'yes',
    schema: itemThingXsd,
    binding: itemThingXjb) {
   produces(dir: itemThingDir, includes: '*.java')
  }
 }
}

Following an example I found on a blog or website somewhere about making gradle build incrementally, I added the inputs/outputs to the xjc task above.

When the xsd is changed, this works like a charm.

However, when we first checkout our workspace, the xjc task evaluates this as a “no change to compile” situation and the stubs do not get built (possibly b/c the output directory timestamp matches the input file timestamps?)

Can anyone give me some hints on how to resolve this issue? I have done my best to research this in documentation, google, etc., but I haven’t found a lot of good info.


(Peter Niederwieser) #2

I’m not exactly sure what you are saying, but one thing that’s suspicious is that the input files reside in the output directory. Instead I’d use different base directories.