简体   繁体   English

如何在gradle build中正确添加jaxb2 setter插件?

[英]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. 我想为gradle构建设置jaxb2 setter插件,以便获取集合属性的setter方法。 There are only examples for maven and ant build files but not for gradle. 只有Maven和ant构建文件的示例,而gradle则没有。

'com.github.jacobono.jaxb' plugin is doing the necessary job but not create setter methods for the collections. “ com.github.jacobono.jaxb”插件正在完成必要的工作,但未为集合创建设置方法。

Please help me on this issue to generate the setter methods for above mentioned case along with java file generation in the gradle build. 请帮助我解决此问题,以在gradle构建中生成上述情况的setter方法以及Java文件生成。

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 { buildscript {

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

} }

apply plugin: 'com.github.jacobono.jaxb' 应用插件:“ 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 { 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"]
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM