Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.