Chanaka NZ
Chanaka NZ

Reputation: 147

How to add jaxb2 setter plugin correctly in gradle build?

I wanted to set jaxb2 setter plugin for gradle build in order to get the setter methods for collection attributes. There are only examples for maven and ant build files but not for gradle.

'com.github.jacobono.jaxb' plugin is doing the necessary job but not create setter methods for the collections.

Please help me on this issue to generate the setter methods for above mentioned case along with java file generation in the gradle build.

Upvotes: 0

Views: 1737

Answers (1)

Chanaka NZ
Chanaka NZ

Reputation: 147

After some searches I found myself the solution. Hope this might help someone.

This is how I achieved this task after doing the research. This worked as expected. Add followings to your build file.

buildscript {

dependencies {
    classpath 'com.github.jacobono:gradle-jaxb-plugin:1.3.5'
}

}

apply plugin: 'com.github.jacobono.jaxb'

dependencies {

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'
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.5"
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics:0.6.4"
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics-annotate:0.6.4"
jaxb "org.jvnet.jaxb2_commons:jaxb2-value-constructor:3.0"

}

jaxb {

System.setProperty('javax.xml.accessExternalSchema', 'all') //To solve external schema dependencies
xsdDir = "src/main/resources/schema/" //xsd directory
xjc {
    taskClassname = "org.jvnet.jaxb2_commons.xjc.XJC2Task" // This is for setter plugin
    args = ["-Xsetters","-Xsetters-mode=direct"]
}

}

Upvotes: 1

Related Questions