Skip to content

Latest commit

 

History

History
101 lines (81 loc) · 2.32 KB

README.adoc

File metadata and controls

101 lines (81 loc) · 2.32 KB

Gradle Plugin for Jakarta JAXB binding generation (XJC)

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.

Apply the plugin
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.

Configure the output dir
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:

Configure schemas
xjc {
    schemas {
        ...
    }
}

Minimally you must define the XSD and binding file to use:

Schema config basic
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):

Schema config extensions
xjc {
    ...
    schemas {
        mapping {
            xsdFile = "path/to/mapping.xsd"
            xjcBindingFile = "path/to/mapping.xjb"
            xjcExtensions += ['inheritance', 'simplify']
        }
        ...
    }
}
Putting it all together
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']
        }
    }
}