Skip to content

Instantly share code, notes, and snippets.

@breskeby
Created October 8, 2014 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breskeby/b829eca7c1a37e5e4e05 to your computer and use it in GitHub Desktop.
Save breskeby/b829eca7c1a37e5e4e05 to your computer and use it in GitHub Desktop.
simple jaxb source generation with gradle
apply plugin:'idea'
apply plugin:'groovy'
repositories{
jcenter()
}
configurations{
jaxb
}
dependencies{
compile "org.codehaus.groovy:groovy-all:2.3.7"
jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41'
jaxb 'com.sun.xml.bind:jaxb-impl:2.2.7-b41'
jaxb 'javax.xml.bind:jaxb-api:2.2.7'
}
task generateJaxb {
ext.destDir = new File(buildDir, 'generated')
ext.inputDir = new File(projectDir, 'src/xsd')
outputs.dir(destDir)
inputs.dir(inputDir)
doLast{
destDir.mkdirs()
ant.taskdef(name: 'xjc', classname:"com.sun.tools.xjc.XJCTask", classpath: configurations.jaxb.asPath)
ant.xjc(destdir: destDir.absolutePath, package: 'org.acme.demo.model.generated') {
schema(dir:inputDir.absolutePath, includes: '*.xsd')
}
}
}
sourceSets {
main {
groovy{
srcDir generateJaxb.destDir
}
}
}
ideaModule.dependsOn generateJaxb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment