I have a set of gradle build script that uses JAXB to generate Java classes from XSD. I am able to generate the Java classes, however the classes seems to be missing dependencies and will not compile.
build.gradle
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
configurations {
jaxb
}
repositories {
mavenCentral()
}
task genJaxb {
ext.sourcesDir = "${buildDir}/generated/jaxb"
outputs.dir sourcesDir
doLast() {
project.ant {
// Create output directories
mkdir(dir: sourcesDir)
taskdef name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxb.asPath
xjc(destdir: sourcesDir) {
schema(dir: "${projectDir}/src/main/xsd", includes: '**/*.xsd')
produces(dir: sourcesDir, includes: '**/*.java')
}
}
}
}
build.dependsOn genJaxb
dependencies {
compile(files(genJaxb.sourcesDir).builtBy(genJaxb))
jaxb 'com.sun.xml.bind:jaxb-xjc:2.1.7'
compile 'javax.xml.bind:jaxb-api:2.2.3'
}
When I had the generated file directory into the build path, the classes seem to be missing several dependencies.
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
I tried adding the missing dependency but I never see it get downloaded.