- Notifications
You must be signed in to change notification settings - Fork4
This plugin makes it easy to generate Java source code from XML schema files (.xsd). Internally the plugin relies on the JAXB2
License
GradleUp/jaxb2
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This started as a fork fromewerk/gradle-plugins/jaxb2.
This plugin makes it easy to generate Java source code from XML schema files (.xsd). Internallythe plugin relies on the JAXB2 ant task for generating the code. The examples below show howthe plugin can be used.
At the moment the plugin is simplistic and just supports creating Java code from XSD. JAXB2specific special stuff like binding files or additional task parameters are currently notsupported but can surely make it into the plugin in future.
The plugin creates a own 'jaxb2' configuration and adds it to the project. Then it adds all neededdependencies to execute the JAXB ant task. You may need to extend are change these dependencies.As we have thejaxb2
configuration, you can do this by using the defaultdependencies {}
closure of your project. This is shown in the examples below.
The full qualified name of the JAXB2 ant task the does the real work.Defaults toorg.jvnet.jaxb2_commons.xjc.XJC2Task
.Normally there will be need to change this.
This is the container for configuring the distinct generation steps. It can be repeated as neededwithin thejaxb2
extension. The container structure is as follows:
xjc {'generation-step-name' {// optional, defaults to src/generated/java generatedSourcesDir='any/relative/path'// full qualified base package for the classes to be generated basePackage='com.any.app'// relative path the XSD file to generate the code from schema='src/main/xsd/any-file.xsd'// relative path to directory including binding files// all files of pattern **/*.xjb will be included// default to null (no binding files used)// Optional, can be left away bindingsDir='src/main/xsb'// comma separated list of binding file includes// falls back to '**/*.xjb' if not specified includedBindingFiles='any.xjb, subdir/test.xjb' additionalArgs='-nv -dtd'// output encoding of the generated files encoding='UTF-8' }}
Use via Gradle plugin portal
Plugin page, Groovy & Kotlin DSL:https://plugins.gradle.org/plugin/com.github.gradlecommunity.jaxb2
plugins { id'com.github.gradlecommunity.jaxb2' version'3.1.0'}
Full configuration example
plugins { id'com.github.gradlecommunity.jaxb2' version'3.1.0'}repositories { mavenCentral()}// the whole dependency container could be left outdependencies {// default JAXB2 libs added by the plugin jaxb2'org.jvnet.jaxb2_commons:jaxb2-basics-runtime:0.9.5' jaxb2'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.9.5' jaxb2'org.jvnet.jaxb2_commons:jaxb2-basics:0.9.5'// default JAXB libs added by the plugin jaxb2'com.sun.xml.bind:jaxb-core:2.2.11' jaxb2'com.sun.xml.bind:jaxb-xjc:2.2.11' jaxb2'com.sun.xml.bind:jaxb-impl:2.2.11'// any custom libraries here jaxb2'com. …'}jaxb2 { xjc {'request-classes' { basePackage='com.any.app.model.request' schema='src/main/xsd/request.xsd' encoding='UTF-8' extension=true } } xjc {'response-classes' { basePackage='com.any.app.model.response' schema='src/main/xsd/response.xsd' bindings='src/main/xsb' } }}
Minimal configuration example
plugins { id'com.github.gradlecommunity.jaxb2' version'3.1.0'}repositories { mavenCentral()}jaxb2 { xjc {'request-classes' { basePackage='com.any.app.model.request' schema='src/main/xsd/request.xsd' } }}
About
This plugin makes it easy to generate Java source code from XML schema files (.xsd). Internally the plugin relies on the JAXB2