Gradle jaxb2 plugin

Gradle plugin for jaxb2

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.gradleup
ArtifactId

ArtifactId

jaxb2
Last Version

Last Version

3.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Gradle jaxb2 plugin
Gradle plugin for jaxb2
Project URL

Project URL

https://github.com/GradleUp/jaxb2
Source Code Management

Source Code Management

https://github.com/GradleUp/jaxb2/

Download jaxb2

How to add to project

<!-- https://jarcasting.com/artifacts/com.gradleup/jaxb2/ -->
<dependency>
    <groupId>com.gradleup</groupId>
    <artifactId>jaxb2</artifactId>
    <version>3.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.gradleup/jaxb2/
implementation 'com.gradleup:jaxb2:3.2.0'
// https://jarcasting.com/artifacts/com.gradleup/jaxb2/
implementation ("com.gradleup:jaxb2:3.2.0")
'com.gradleup:jaxb2:jar:3.2.0'
<dependency org="com.gradleup" name="jaxb2" rev="3.2.0">
  <artifact name="jaxb2" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.gradleup', module='jaxb2', version='3.2.0')
)
libraryDependencies += "com.gradleup" % "jaxb2" % "3.2.0"
[com.gradleup/jaxb2 "3.2.0"]

Dependencies

test (5)

Group / Artifact Type Version
org.hamcrest : hamcrest-core jar 1.3
org.junit : junit-bom jar 5.6.2
org.junit.jupiter : junit-jupiter-api jar
org.spockframework : spock-core jar 1.3-groovy-2.5
org.apache.commons : commons-io jar 1.3.2

Project Modules

There are no modules declared in this project.

License Build Status

JAXB2 plugin

This is a fork from ewerk/gradle-plugins/jaxb2.

The thing we needed to be fixed has been fixed upstreams, so please migrate back to ewerk/gradle-plugins/jaxb2. There are additional things to work on.

Description

This plugin makes it easy to generate Java source code from XML schema files (.xsd). Internally the plugin relies on the JAXB2 ant task for generating the code. The examples below show how the plugin can be used.

At the moment the plugin is simplistic and just supports creating Java code from XSD. JAXB2 specific special stuff like binding files or additional task parameters are currently not supported but can surely make it into the plugin in future.

Please have a look at the plugins change log.

Dependency management

The plugin creates a own 'jaxb2' configuration and adds it to the project. Then it adds all needed dependencies to execute the JAXB ant task. You may need to extend are change these dependencies. As we have the jaxb2 configuration, you can do this by using the default dependencies {} closure of your project. This is shown in the examples below.

Configuration

taskName

The full qualified name of the JAXB2 ant task the does the real work. Defaults to org.jvnet.jaxb2_commons.xjc.XJC2Task. Normally there will be need to change this.

xjc

This is the container for configuring the distinct generation steps. It can be repeated as needed within the jaxb2 extension. The container structure is as follows:

xjc {
  'generation-step-name' {
    // optional, defaults to src/generated/java
    generatedSourcesDir = 'any/relative/path'
    
    // full qualified base package for the classes to be generated
    basePackage = 'com.any.app'
    
    // relative path the XSD file to generate the code from
    schema = 'src/main/xsd/any-file.xsd'
    
    // relative path to directory including binding files
    // all files of pattern **/*.xjb will be included
    // default to null (no binding files used)
    // Optional, can be left away
    bindingsDir = 'src/main/xsb'
    
    // comma separated list of binding file includes
    // falls back to '**/*.xjb' if not specified
    includedBindingFiles = 'any.xjb, subdir/test.xjb'
    
    additionalArgs = '-nv -dtd'

    // output encoding of the generated files
    encoding = 'UTF-8'
  }
}

Examples

Use via Gradle plugin portal

plugins {
  id 'com.github.gradlecommunity.jaxb2' version '0.1.0'
}

Full configuration example

plugins {
  id 'com.github.gradlecommunity.jaxb2' version '0.1.0'
}

repositories {
  mavenCentral()
}

// the whole dependency container could be left out
dependencies {
  // default JAXB2 libs added by the plugin
  jaxb2 'org.jvnet.jaxb2_commons:jaxb2-basics-runtime:0.9.5'
  jaxb2 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.9.5'
  jaxb2 'org.jvnet.jaxb2_commons:jaxb2-basics:0.9.5'

  // default JAXB libs added by the plugin
  jaxb2 'com.sun.xml.bind:jaxb-core:2.2.11'
  jaxb2 'com.sun.xml.bind:jaxb-xjc:2.2.11'
  jaxb2 'com.sun.xml.bind:jaxb-impl:2.2.11'
  
  // any custom libraries here
  jaxb2 'com. …'
}

jaxb2 {
  xjc {
    'request-classes' {
      basePackage = 'com.any.app.model.request'
      schema = 'src/main/xsd/request.xsd'
      encoding = 'UTF-8'
      extension = true 
    }
  }

  xjc {
    'response-classes' {
      basePackage = 'com.any.app.model.response'
      schema = 'src/main/xsd/response.xsd'
      bindings = 'src/main/xsb'
    }
  }
}

Minimal configuration example

plugins {
  id 'com.github.gradlecommunity.jaxb2' version '1.0.2'
}

repositories {
  mavenCentral()
}

jaxb2 {
  xjc {
    'request-classes' {
      basePackage = 'com.any.app.model.request'
      schema = 'src/main/xsd/request.xsd'
    }
  }
}
com.gradleup

Versions

Version
3.2.0
3.0.0