Santosh Gokak
Santosh Gokak

Reputation: 3411

Gradle : Generating sources from WSDL & XSD and adding it to main classpath for compilation

I am failry new to gradle and have a multiproject gradle build to which want to add a WSDL2Java related tasks to one of the project. I have coded the necessary tasks to generate,compile,package the generated stubs into a jar and add it to the classpath. Now , i want to perform these tasks before the java compilation is started.

Below is how i coded the new tasks

task genClasses(type: JavaExec) {
//Run WSDL2Java and generate java source files.
}

task compileClasses(dependsOn:'genClasses'){
//Use ant.javac or add type:JavaCompile in task defination as shown below
// task compileClasses(dependsOn:'genClasses',type:JavaCompile)
}

task packageClasses(dependsOn:'compileClasses',type:Jar){
//package my jar
}

task createStubs(dependsOn: 'packageClasses'){
    //add created jar to the classpath
}

compileJava.dependsOn createStubs

The build fails with exception and shows below message

Circular dependency between tasks. Cycle includes [task ':projectx:genWsdlClasses', task ':projectx:classes'].

I figured out that the compileClasses tasks somehow is causing this circular dependency, but not sure how to get rid of it?

Are there any other better or idiomatic ways to perform this source generation, compilation of generated source,packaging and adding it to the main sourceset classpath before the main source gets build?

Upvotes: 1

Views: 9613

Answers (2)

nilsmagnus
nilsmagnus

Reputation: 2322

Use the plugin "no.nils.wsdl2java"

https://plugins.gradle.org/plugin/no.nils.wsdl2java

The plugin takes care of hooking it in to the build and clean tasks.

Upvotes: 0

Spina
Spina

Reputation: 9366

I use the Jaxb-Plugin available here. My Gradle build file looks like this:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'no.entitas.gradle.jaxb:gradle-jaxb-plugin:2.0'
  } 
}

dependencies {
  jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.5-1'
  jaxb 'com.sun.xml.bind:jaxb-impl:2.2.5-1'
}

generateSchemaSource.destinationPackage = "my.custom.package"

I believe that this will create the jaxb classes that you want. Does that help?

Upvotes: 1

Related Questions