❗IMPORTANT PLUGIN ID CHANGES❗
This plugin is an update to the original project this was forked from.
We acknowledge and are grateful to these developers for their contributions to open source.
You can find the source code of their original using the forked from
link of this project.
In compliance with the license chosen by the original author, we are publishing this modified version since they have not kept up with the maintenance needs of the community.
To prevent possible collisions and/or confusion if the original author decides to accept our PR’s or to simply begin anew, we have changed the id and package names.
In compliance with the gradle plugin submission guidelines, the plugin’s id was changed from com.github.jacobono.jaxb
to org.openrepose.gradle.plugins.jaxb
.
This affects how you apply the plugin (apply plugin: 'org.openrepose.gradle.plugins.jaxb'
).
This Gradle plugin defines some conventions for XSD projects and provides some processing to ease some of the maintenance of these projects by:
-
Hooking in ant tasks to parse the XSD’s with the
xjc
task. -
Generates code from XSD’s per unique namespace.
-
Generates an xsd dependency tree, to parse namespaces in their order of dependencies, from the base namespaces up.
-
Generating an episode file for every unique namespace in a set of xsd files.
-
Defining a convention to optionally generate episode files.
-
Ability to define xsd projects to depend on one another, so that when parsing, what a project depends on is also parsed.
See this plugin’s page in the gradle plugins repo.
You need the jaxb configuration to run the xjc
task, but that is the only task that requires an external dependency.
If an XJC plugin is used, then simply add it to the dependencies to have it included.
Any version of jaxb that you care to use will work.
dependencies {
jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
xjc 'com.example:xjc-plugin:0.0.0'
}
There are only two tasks.
-
xjc
-
runs
xjc
ant task on each.xsd
in the dependency tree. -
needs to be run manually.
-
-
xsd-dependency-tree
-
Builds a dependency tree from all
.xsd
files configured to be parsed. -
Finds each unique namespace and groups files containing that namespace.
-
Analyzes xsd dependencies and places them in the correct place in the dependency tree. This ensures the namespaces can be parsed in order using the optionally generated episode files to bind. If the episode files generated, then other projects can bind to them from the namespace in the tree.
-
This keeps all namespaces decoupled and prevents a big episode blob containing everything that was parsed.
-
xjc
depends on xsd-dependency-tree
so you don’t need to run the tree task at all.
There are two conventions that can be overridden and one is nested in the other.
The jaxb
convention defines the conventions for the whole plugin, and the xjc
convention defines the conventions for the xjc
ant task.
You can change these defaults with a closure in your build script.
jaxb {
...
xjc {
...
}
}
These are the configurable parameters for the JAXB Plugin.
Parameter |
Description |
Default |
Type |
|
Defined by each project to tell the plugin where to find the |
|
|
|
RegEx used to produce a List of files found in |
|
|
|
All generated episode files go directly under here, no subfolders. (i.e. "build/generated-resources/episodes", "episodes", "schema/episodes", "xsd/episodes", "XMLSchema/episodes") |
|
|
|
User defined binding files to pass into the |
|
|
|
RegEx used to produce a List of customization files found in |
|
|
These are the configurable parameters for the JAXB Plugin’s XJC interactions.
Parameter |
Description |
Default |
Type |
|
Enables a custom task classname to run the XJC task if something other than JAXB is desired. Useful if JAXB2 is required to be used. |
|
|
|
The directory relative to In order to automatically remove previously generated sources, this directory is deleted whenever the Up To Date check fails. This should never point to a location under the main source directory. |
|
|
|
This parameter has never been used by this plugin. It remains only for the purposes of backwards compatibility. Consider it deprecated and that it will be removed in a future release. |
|
|
|
Enables the creation of the Episode files |
|
|
|
Run XJC compiler in extension mode |
|
|
|
Only used with nested |
|
|
|
generates a header in each generated file |
|
|
|
specify a package to generate to |
Not Defined |
|
|
List of extra String arguments to pass the |
Empty String |
|
|
Enables setting the new |
Implementation Specific |
|
For more in depth description please see the XJC Ant Task documentation.
Customized to use xjc
plugins.
dependencies {
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1"
jaxb 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:1.11.1'
jaxb 'org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.0.4'
jaxb 'org.slf4j:slf4j-log4j12:1.7.25'
}
jaxb {
xsdDir = "${project.projectDir}/some/folder"
xjc {
generateEpisodeFiles = false
taskClassname = "org.jvnet.jaxb2_commons.xjc.XJC2Task"
generatePackage = "com.company.example"
args = ["-Xinheritance", "-Xannotate"]
}
}
Create a convention for xsd projects to have a suffix of -schema
, then it is easy to write:
subprojects { project ->
if(project.name.endsWith("-schema")) {
apply plugin: 'org.openrepose.gradle.plugins.jaxb'
dependencies {
jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
}
}
}
applying the plugin to all schema projects.
Another way to do this is by adding a boolean property to the gradle.properties
file in the sub-projects.
You can then use it this way:
subprojects { project ->
if(Boolean.valueOf(project.getProperties().getOrDefault('doJAXB', 'false'))) {
apply plugin: 'org.openrepose.gradle.plugins.jaxb'
dependencies {
jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
}
}
}
This lets gradle know that the xjc task of a project is dependent on the xjc task of another project. This can be achieved with:
dependencies {
jaxb project(path: ':common', configuration: 'jaxb')
}
This expresses that xsd’s definitely depend on other xsd’s outside of their parent folder xsdDir
.
This will run the xjc task on common
before running the xjc task of of the project this is defined in.
You can find some small example projects using this plugin in the examples folder.
Simply issue ../gradlew clean build
from within it to run them all.
For a basic example of using this plugin with multiple sub-projects that have interactions, please see this test project.
For a real world example of this plugin, please visit the main Repose project.