Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
Created November 14, 2012 09:07
Show Gist options
  • Save aphexmunky/4071113 to your computer and use it in GitHub Desktop.
Save aphexmunky/4071113 to your computer and use it in GitHub Desktop.
JAXB task in gradle
def generatedResources = "src/main/generated-sources"
task jaxb(){
description 'Converts xsds to classes'
def jaxbTargetDir = file( generatedResources )
jaxbTargetDir.deleteDir()
doLast {
jaxbTargetDir.mkdirs()
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxb.asPath)
ant.jaxbTargetDir = jaxbTargetDir
ant.xjc(destdir: '${jaxbTargetDir}', package: 'com.thehutgroup.xml.representation') {
schema(dir:'XSD/Representation', includes: '*.xsd')
}
ant.xjc(destdir: '${jaxbTargetDir}', package: 'com.thehutgroup.xml.event') {
schema(dir:'XSD/Event', includes: '*.xsd')
}
}
}
task generateSources(dependsOn: jaxb) {
description 'generates the resources defined by the external xsd\'s'
}
@bmiczek
Copy link

bmiczek commented Jul 21, 2014

Found your blog post while searching for a fix for the compile issue. I'll link it here in case anyone else runs into it:
http://squidoop.blogspot.com/2012/11/jaxb-generation-using-gradle.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment