Gradle plugin for running XJC which generates JAXB binding classes from an XSD schema and optional binding files.
This version uses the Jakarta version of XJC.
It allows configuration of one-or-more schemas and generates a task for performing XJC against each. While the task can be applied and configured on its own, here we will focus on explaining use of the plugin and extension to wire everything up.
plugins {
id "org.hibernate.build.xjc-jakarta"
}
The plugin registers an extension named xjc
which can be used to configure stuff. The main configuration being the
base output directory. Each task will have its own output directory relative to this extension-level one.
xjc {
// "${buildDir}/generated/sources/xjc/main" by default
outputDirectory = project.getLayout().getBuildDirectory().dir( "some/other/dir" )
}
Each schema upon which to perform XJC is defined and configured through a NamedDomainObjectContainer
named schemas
on the xjc
extension:
xjc {
schemas {
...
}
}
Minimally you must define the XSD and binding file to use:
xjc {
...
schemas {
config {
xsdFile = "path/to/config.xsd"
xjcBindingFile = "path/to/config.xjb"
}
...
}
}
Optionally, XJC extensions may be enabled (assuming the appropriate jars are added to the xjc
Configuration):
xjc {
...
schemas {
mapping {
xsdFile = "path/to/mapping.xsd"
xjcBindingFile = "path/to/mapping.xjb"
xjcExtensions += ['inheritance', 'simplify']
}
...
}
}
xjc {
outputDirectory = project.getLayout().getBuildDirectory().dir( "some/other/dir" )
schemas {
config {
xsdFile = "path/to/config.xsd"
xjcBindingFile = "path/to/config.xjb"
}
mapping {
xsdFile = "path/to/mapping.xsd"
xjcBindingFile = "path/to/mapping.xjb"
xjcExtensions += ['inheritance', 'simplify']
}
}
}