Gradle plugin for XJC integration

Integrates JAXB XJC functionality into a Gradle build

License

License

Categories

Categories

Gradle Build Tools Hibernate Data ORM
GroupId

GroupId

org.hibernate.build.gradle
ArtifactId

ArtifactId

gradle-xjc-plugin
Last Version

Last Version

1.0.2.Final
Release Date

Release Date

Type

Type

jar
Description

Description

Gradle plugin for XJC integration
Integrates JAXB XJC functionality into a Gradle build
Project URL

Project URL

https://github.com/sebersole/gradle-xjc-plugin
Source Code Management

Source Code Management

https://github.com/sebersole/gradle-xjc-plugin

Download gradle-xjc-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/org.hibernate.build.gradle/gradle-xjc-plugin/ -->
<dependency>
    <groupId>org.hibernate.build.gradle</groupId>
    <artifactId>gradle-xjc-plugin</artifactId>
    <version>1.0.2.Final</version>
</dependency>
// https://jarcasting.com/artifacts/org.hibernate.build.gradle/gradle-xjc-plugin/
implementation 'org.hibernate.build.gradle:gradle-xjc-plugin:1.0.2.Final'
// https://jarcasting.com/artifacts/org.hibernate.build.gradle/gradle-xjc-plugin/
implementation ("org.hibernate.build.gradle:gradle-xjc-plugin:1.0.2.Final")
'org.hibernate.build.gradle:gradle-xjc-plugin:jar:1.0.2.Final'
<dependency org="org.hibernate.build.gradle" name="gradle-xjc-plugin" rev="1.0.2.Final">
  <artifact name="gradle-xjc-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.hibernate.build.gradle', module='gradle-xjc-plugin', version='1.0.2.Final')
)
libraryDependencies += "org.hibernate.build.gradle" % "gradle-xjc-plugin" % "1.0.2.Final"
[org.hibernate.build.gradle/gradle-xjc-plugin "1.0.2.Final"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Gradle XJC Plugin

This is a plugin for performing XJC generation (JAXB binding model generation) as part of a Gradle build. This plugin is different from others I looked into using in that it centers around defining XJC for specific schemas. Other JAXB/XJC plugins (https://github.com/jacobono/gradle-jaxb-plugin e.g.) centered around directories. And maybe that is the better approach overall and the approach here simply shows my lack of fu with JAXB and XJC in general. But this is what I need for the Hibernate build and so here is the plugin for that style of XJC processing.

Usage

To use the plugin, you must first get it added to your build:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.hibernate.build.gradle:gradle-xjc-plugin:<version>'
    }
}

apply plugin: 'org.hibernate.build.gradle.xjc'

where <version> is the version you want to use.

This plugin uses the XJC Ant task (ultimately I'd like to get away from the Ant usage). However, it does not assume any particular XJC Ant task. You need to tell it the particular Ant task to use as well as the dependencies needed for loading that Ant task. The plugin adds a configuration named xjc where you can add the needed dependencies. The plugin does automatically add gradleApi() as a xjc dependency because the newer jvnet tasks seem to rely on slf4j, so we pass the version of slf4j used by the running Gradle. However, all (other) dependencies needed for the the Ant task need to be defined here. E.g.:

dependencies {
    xjc 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
    xjc 'org.jvnet.jaxb2_commons:jaxb2-basics:0.9.3'
    xjc 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.9.3'
}

The plugin also adds an extension for configuring its processing. Along with the above dependencies, you should tell it the specific Ant task to use:

xjc {
    xjcTaskName = 'org.jvnet.jaxb2_commons.xjc.XJC2Task'
}

By default, the plugin will generate all output to ${project.buildDir}/generated-src/xjc/main (packages are created under this directory). You can instruct the plugin to use a different directory:

xjc {
    outputDir = 'some/other/dir'
}

The plugin makes use of a Gradle feature called a NamedDomainObjectContainer. Basically, it allows dynamic extension of the DSL for in an a posteriori manner. For what its worth, this is how many things in Gradle itself (like Configurations, SourceSets, etc) work. The plugin defines a schemas NamedDomainObjectContainer under the xjc extension. The type of the domain objects in this container (of type org.hibernate.build.gradle.xjc.SchemaDescriptor) describe the processing for a particular XSD. Let see an example:

xjc {
    ...
    // access the schemas NamedDomainObjectContainer
    schemas {

        // and add a new SchemaDescriptor to it under the name 'cfg'
        cfg {
            // and now, configure the SchemaDescriptor
            xsd = file( 'src/main/resources/org/hibernate/xsd/cfg/legacy-configuration-4.0.xsd')
            xjcBinding = file( 'src/main/xjc-bindings/hbm-configuration-bindings.xjb' )
        }

        // and add a new SchemaDescriptor to it under the name 'hbm'
        hbm {
            xsd = file( 'src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd' )
            xjcBinding = file( 'src/main/xjc-bindings/hbm-mapping-bindings.xjb' )
            xjcExtensions = ['inheritance', 'simplify']
        }
    }
}

SchemaDescriptor allows configuration of:

  • xsd - The XSD schema
  • xjcBinding - The XJC binding file to apply
  • xjcExtensions - Any XJC extensions to be enabled (appropriate dependencies should be defined using xjc configuration)
  • jaxbVersion - The JAXB version to target. Defaults to 2.0

Versions

Version
1.0.2.Final
1.0.1.Final
1.0.0.Final