This plugin generates Java code from schema files (see com.sun.tools.xjc.XJCTask) or schema files from existing Java code (see com.sun.tools.jxc.SchemaGenTask).
To apply the JAXB Gradle Plugin to your projects, add the following in your build script:
plugins {
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
jaxb {
// generate java code from schema
javaGen {
//generates a 'project' schema file from existing java code
name {
schema = file('schema.xsd')
binding = file('binding.xjb')
}
}
//generates schema from java code
schemaGen {
//generates java code for project from project schema
name {
javaFiles = fileTree(dir: 'src/main/java', include: 'com/corporate/annotated/**/binding/**/*.java')
namespaceconfigs = [ 'http://www.corporate.com/xml/ns/corporate/feature/1.0' : 'feature.xsd' ]
}
}
}
If the JavaBasePlugin is applied to the project, generated java sources will be added to the specified source set. Per default the main source set is used.
Important
|
This plugin uses the version 2.2.11. It is possible to change this to 2.2.7 or 2.2.10. It will not work with older versions of JAXB. It is possible to overwrite the project dependency configuration 'jaxb', if you want use an other version of JAXB. The classpath of the xjc can be extended with a project configuration 'jaxb' and dependencies. |
The JAXB Gradle plugin adds one task jaxb
to the project. This task depends on all other plugin task. It is a task added for each configuration in schemaGen and javaGen.
Task name |
Type |
Description |
jaxb |
Task |
Overall |
jaxbJavaGen<configuration name> |
com.intershop.build.jaxb.task.SchemaToJavaTask |
This task generates Java code for the specified schema and binding configuration. |
jaxbSchemaGen<configuration name> |
com.intershop.build.jaxb.task.JavaToSchemaTask |
This task creates schema files for the specified java code. |
This plugin adds an extension jaxb
to the project.
Method | Values | Description |
---|---|---|
javaGen |
This contains all Java code generation configurations. |
|
schemaGen |
This contains all schema code generation configurations. |
Property | Type | Default value | Description |
---|---|---|---|
outputDir |
|
|
Generated code will be written under this directory. |
args |
|
Additional command line arguments passed to the XJC (-use-runtime, -schema, -dtd, -relaxng, -Xlocator, -Xsync-methods) |
|
sourceSetName |
|
|
Generated source code will be added to the source set. |
encoding |
|
|
specify character encoding for generated source files |
strictValidation |
|
|
perform strict validation of the input schema |
extension |
|
|
allow vendor extensions - do not strictly follow the |
header |
|
|
Generate a header in each generated file indicating that this file is generated by such and such version of JAXB RI when. |
packageName |
|
|
If specified, generated code will be placed under this Java package. |
schema |
|
|
A schema file to be compiled. |
binding |
|
|
An external binding file that will be applied to the schema file. |
catalog |
|
|
Specify the catalog file to resolve external entity references. Support TR9401, XCatalog, and OASIS XML Catalog format. See the catalog-resolver sample for details. |
schemas |
|
|
To compile more than one schema at the same time, use this configuration. |
bindings |
|
|
To specify more than one external binding file at the same time, use this configuration. |
targetVersion |
|
|
Specifies the runtime environment in which the generated code is supposed to run. Expects also 2.0 or 2.1 values. This allows more up-to-date versions of XJC to be used for developing applications that run on earlier JAXB versions. |
language |
|
|
Specifies the schema language to compile. Supported values are "WSDL", "XMLSCHEMA", and "WSDL." Case insensitive. |
antTaskClassName |
|
|
The JAXB tools (e.g. XJC) bundled with the JDK are relocated to a package not matching the JAXB-RI. There are a lot of XJC plugins around compiled against the JAXB-RI which cannot be used with the JAXB tools bundled with the JDK due to this. When configuring the plugin to use the JAXB-RI Ant task instead of the Ant task bundled with the JDK (e.g. com.sun.tools.xjc.XJC2Task), those plugins can be used. |
Property | Type | Default value | Description |
---|---|---|---|
outputDir |
|
|
Base directory to place the generated schema files |
javaFiles |
|
|
Source files configuration. |
namespaceconfigs |
|
|
Control the file name of the generated schema. The entry key is the namespace attribute and the value is the file name. When this element is present, the schema document generated for the specified namespace will be placed in the specified file name. |
episode |
|
|
If specified, generate an episode file in the specified name. |
plugins {
id 'java'
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
jaxb {
javaGen {
posConfig {
packageName = ''
schema = file('pos.xsd')
}
}
}
plugins {
id 'java'
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
jaxb {
javaGen {
posConfig {
binding = file('binding.xjb')
schema = file('pos.xsd')
}
}
}
plugins {
id 'java'
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
jaxb {
javaGen {
ublConfig {
binding = file('ubl.xjb')
schemas = fileTree(dir: 'cd-UBL-1.0/xsd', include: '**/*.xsd')
}
}
}
plugins {
id 'java'
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
def xewFile = file('staticfiles/definition/xew-includes.txt')
def args = ['-Xxew', '-Xxew:instantiate early', '-Xxew:delete', "-Xxew:includeFile \${xewFile.absolutePath.replace('\\','/')}"]
configurations {
xjc
}
jaxb {
javaGen {
gcdm {
schemas = fileTree(dir: 'staticfiles/definition', include: '**/**/*.xsd')
binding = file('staticfiles/definition/gcdm-customer-binding.xjb')
strictValidation = false
extension = true
arg.addAll(args)
}
}
}
dependencies {
xjc 'com.github.jaxb-xew-plugin:jaxb-xew-plugin:1.1'
}
plugins {
id 'java'
id 'com.intershop.gradle.jaxb' version '2.0.0'
}
jaxb {
schemaGen {
orderstatusimport {
javaFiles = fileTree(dir: 'javasource', include: 'com/corporate/annotated/**/binding/**/*.java')
namespaceconfigs = ['http://com.corporate.com/xml/ns/corporate/feature/status/1.0' : 'feature_xml.xsd' ]
}
}
}
Copyright 2014-2016 Intershop Communications.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.