Skip to content

Jakarta version of the XJC plugin used in the Hibernate build

License

Notifications You must be signed in to change notification settings

sebersole/xjc-plugin-jakarta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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']
        }
    }
}

About

Jakarta version of the XJC plugin used in the Hibernate build

Resources

License

Stars

Watchers

Forks

Packages

No packages published