0

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.

ghost013
  • 97
  • 1
  • 10
  • i can see those import classes in "javax.xml.bind:jaxb-api:2.2.3". maybe you can change dependency type to "implementation" from "compile" and see if it works. https://stackoverflow.com/questions/44493378/whats-the-difference-between-implementation-and-compile-in-gradle – taiyebur Mar 31 '20 at 04:09
  • @taiyebur I tried your suggestion, but still the same result. The issue is I do not see the jaxbi-api jar in my external dependencies folder. – ghost013 Mar 31 '20 at 04:34
  • 1
    you can check this one and see if dependencies download. https://stackoverflow.com/questions/38485819/gradle-build-doesnt-download-dependencies – taiyebur Mar 31 '20 at 05:43

0 Answers0