Giter VIP home page Giter VIP logo

xjc-gradle-plugin's Introduction

Gradle Plugin Release GitHub Actions status

xjc-gradle-plugin

A Gradle plugin for running the XJC binding compiler to generate Java source code from XML schemas (xsd files) using JAXB.

Requirements and features

  • The plugin requires Gradle version 6.7 or later.
  • It has been tested with Java 8 and Java 17.
  • It has been tested with XJC version 2.3.3 (using the javax namespace) and 3.0.2 (using the jakarta namespace). Defaults to the jakarta variant.
  • It supports the Gradle build cache (enabled by setting "org.gradle.caching=true" in your gradle.properties file).
  • It supports the Gradle configuration cache (enabled by setting org.gradle.configuration-cache=true in your gradle.properties file").
  • It supports project relocation for the build cache (e.g. you move your project to a new path, or make a new copy/clone of it). This is especially useful in a CI context, where you might clone PRs and/or branches for a repository in their own locations.
  • It supports parallel execution (enabled with "org.gradle.parallel=true", possibly along with "org.gradle.priority=low", in your gradle.properties file).
  • It supports most, but not all (yet), of the functionality provided by XJC. Check the configuration section and the road map section to get an idea of what is possible.

Configuration

Apply the plugin ID "com.github.bjornvester.xjc" as documented in the Gradle Plugin portal page, e.g. like this:

plugins {
    id("com.github.bjornvester.xjc") version "1.8.1"
}

You can configure the plugin using the "xjc" extension like this:

xjc {
    // Set properties here...
}

Here is a list of all available properties:

Property Type Default Description
xsdDir DirectoryProperty "$projectDir/src
/main/resources"
The directory holding the xsd files to compile.
includes ListProperty<String> [empty] An optional include pattern for the files in the xsdDir property
excludes ListProperty<String> [empty] An optional exclude pattern for the files in the xsdDir property
bindingFiles ConfigurableFileCollection xsdDir.asFileTree.matching
{ include("**/*.xjb") }
The binding files to use in the schema compiler
outputJavaDir DirectoryProperty "$buildDir/generated
/sources/xjc/java"
The output directory for the generated Java sources.
Note that it will be deleted when running XJC.
outputResourcesDir DirectoryProperty "$buildDir/generated
/sources/xjc/resources"
The output directory for the generated resources (if any).
Note that it will be deleted when running XJC.
useJakarta Provider<Boolean> true Set to use the jakarta namespace. If false, uses the javax namespace. This value determines the default version of XJC and the JAXB binding provider.
xjcVersion Provider<String> "3.0.2" for jakarta /
"2.3.8" for javax
The version of XJC to use.
defaultPackage Provider<String> [not set] The default package for the generated Java classes.
If empty, XJC will infer it from the namespace.
generateEpisode Provider<Boolean> false If true, generates an Episode file for the generated Java classes.
markGenerated Provider<Boolean> false If true, marks the generated code with the annotation @javax.annotation.Generated.
options ListProperty<String> [empty] Options to pass to either the XJC core, or to third party plugins in the xjcPlugins configuration
groups NamedDomainObjectContainer [empty] Allows you to group a set of XSDs and generate sources with different configurations. Requires Gradle 7.0 or higher. See below for details.
addCompilationDependencies Provider<Boolean> true Adds dependencies to the implementation configuration for compiling the generated sources. These includes jakarta.xml.bind:jakarta.xml.bind-api and possibly jakarta.annotation:jakarta.annotation-api.

Choosing which schemas to generate source code for

By default, it will compile all XML schemas (xsd files) found in the src/main/resource folder. You can change to another folder through the following configuration:

xjc {
    xsdDir.set(layout.projectDirectory.dir("src/main/xsd"))
}

All referenced resources must be located under this directory, or up-to-date checking might not work properly.

If you don't want to compile all schemas in the folder, you can specify which ones through the includes and excludes properties. These are both Ant patterns. Here is an example where all schema files are referenced relative to the xsdDir property:

xjc {
    xsdFiles = project.files(
        xsdDir.file("MySchema1.xsd"),
        xsdDir.file("MySchema2.xsd")
    )
    // Or
    xsdFiles = xsdDir.asFileTree.matching { include("subfolder/**/*.xsd") }
}

Customizing the build dependencies

By default, it will use XJC version 3.0.2 to compile the schemas. You can set another version through the xjcVersion property like this:

xjc {
    xjcVersion.set("2.3.8")
    useJakarta.set(false)
}

If you specify a version in the 2.x range, which generates source code with the javax namespace, you should also set the useJakarta configuration to false. Note that setting useJakarta to false, it will by default select an appropriate version in the 2.x range.

By applying the plugin, it will register the Java plugin as well if it isn't there already (so the generated source code can be compiled). It will also by default add the dependency jakarta.xml.bind:jakarta.xml.bind-api to your implementation configuration, as this is needed to compile the source code. If your project is going to be deployed on a Java/Jakarta EE application server, you may want to exclude this dependency from your runtime and instead use whatever your application server is providing. This can be done by setting the configuration addCompilationDependencies to false.

Choosing the file encoding

If your schemas contain characters that do not match your default platform encoding (on western versions of Windows, this will probably be CP-1252), set the encoding through the file.encoding property for Gradle. For example, to use UTF-8, put this in your gradle.property file:

org.gradle.jvmargs=-Dfile.encoding=UTF-8

If you are on a POSIX operating system (e.g. Linux), you may in addition to this need to set your operating system locale to one that supports your encoding. Otherwise, Java (and therefore also Gradle and XJC) may not be able to create files with names outside of what your default locale supports. Especially some Docker images, like the Java ECR images from AWS, are by default set to a locale supporting ASCII only. If this is the case for you, and you want to use UTF-8, you could export an environment variable like this:

export LANG=C.UTF-8

Enabling the use of the @Generated annotation

If you like to have the generated source code marked with the @javax.annotation.Generated annotation, set the markGenerated property to true like this:

xjc {
    markGenerated.set(true)
}

Note that while this annotation is found in the Java 8 SDK, it is not present in Java 9 and later. (However, there is a @javax.annotation.processing.Generated annotation, notice the processing sub-package, but this is not yet supported by this plugin.)

Generating episode files

XJC can generate an episode file, which is basically an extended binding file that specifies how the schema types are associated with the generated Java classes.

You can enable the generation using the generateEpisode property like this:

xjc {
    generateEpisode.set(true)
}

The file will be generated at META-INF/sun-jaxb.episode and added as a resource to the main source set.

Consuming episode files

XJC can consume the episode files so that it is possible to compile java classes from a schema in one project, and consume it in XJC generators in other projects, so you don't have to compile the same schemas multiple times. To do this, you need to add the jar file to the configuration named "xjcBindings". This is done using normal Gradle dependency management.

For multi-projects, assuming the episode file is generated in a project called "test-producer", you can do this like this:

dependencies {
    implementation(project(":test-producer"))
    xjcBindings(project(":test-producer"))
}

Consuming binding files

You can also provide your own binding files (or custom episode files) through the bindingFiles property:

xjc {
    bindingFiles.setFrom(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }) // Files with an .xjb extension in the "src/main/xjb" directory
}

Activating (third party) XJC plugins

To use third party plugins, supply the relevant dependencies to the xjcPlugins configuration. Then set the plugin options through the options property.

For example, to use the "Copyable" plugin from the JAXB2 Basics project, configure the following:

dependencies {
    xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics:0.13.1")
}

xjc {
    options.add("-Xcopyable")
}

Note that the above plugin is only compatible with JAXB 2.x, at least at the time of this writing. There is a fork here that you may try for JAXB 3.x and the jakarta namespace.

If you have trouble activating a plugin and is unsure whether it has been registered, you can run Gradle with the --debug option. This will print additional information on what plugins were found, what their option names are, and what plugins were activated. Note that in order to activate a third-party plugin, you must always provide at least one option (and usually just one) from the plugin.

Supporting Date/Time APIs introduced in Java 8

By default, XJC will map date and time types to difficult-to-use Java types like XMLGregorianCalendar. If you like to use the newer Data/Time APIs from package java.time, you must use a mapper and write a custom binding file.

An example of a mapper project is threeten-jaxb, but there are others as well. If you like to use this one, include it as a dependency:

dependencies {
    implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0") // This version is for Jakarta
}

Then create a binding file with content with the types you like to map:

<bindings xmlns="https://jakarta.ee/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          jaxb:version="3.0"
          jaxb:extensionBindingPrefixes="xjc">
    <globalBindings>
        <xjc:javaType name="java.time.LocalDate" xmlType="xs:date" adapter="io.github.threetenjaxb.core.LocalDateXmlAdapter"/>
        <xjc:javaType name="java.time.LocalDateTime" xmlType="xs:dateTime" adapter="io.github.threetenjaxb.core.LocalDateTimeXmlAdapter"/>
        <xjc:javaType name="java.time.YearMonth" xmlType="xs:gYearMonth" adapter="io.github.threetenjaxb.core.YearMonthXmlAdapter"/>
        <xjc:javaType name="java.time.Duration" xmlType="xs:duration" adapter="io.github.threetenjaxb.core.DurationXmlAdapter"/>
        <xjc:javaType name="java.time.OffsetDate" xmlType="xs:date" adapter="io.github.threetenjaxb.core.OffsetTimeXmlAdapter"/>
        <xjc:javaType name="java.time.OffsetDateTime" xmlType="xs:dateTime" adapter="io.github.threetenjaxb.core.OffsetDateTimeXmlAdapter"/>
    </globalBindings>
</bindings>

The above configuration is for jakarta. For javax, use version 1.2.0 and the binding attributes to xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1".

Lastly, for both jakarta and javax, configure the plugin to use the binding file (in this case it is called src/main/bindings/bindings.xml):

xjc {
    bindingFiles.setFrom(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") })
}

Note that some use .xml as the extension for the binding files, and some use .xjb. This makes no difference to XJC and you can choose whatever you like.

Generate resources with different configurations

The grouping functionality described here requires Gradle 7.0 or higher

If you require building a subset of XSDs with different configurations (e.g. package names), you can use group property. Each group has the same configuration properties as otherwise, except for the XJC version as this can't be controlled individually. The configurations in the outermost block are considered defaults, and you can then override them in each group.

Example:

xjc {
    // Defaults
    markGenerated.set(true)

    groups {
        register("group1") {
            includes.set(listOf("MySchemaWithFunnyChar.xsd"))
            defaultPackage.set("com.example.group1")
        }
        register("group2") {
            includes.set(listOf("MySchemaWithFunnyChar.xsd"))
            defaultPackage.set("com.example.group2")
        }
    }
}

Note that if you enable episode generation, XJC will generate multiple files (one for each group) but with the same name. You will have to merge these yourself. You will also not be able to reference between groups. If you require this, you should instead separate the build into individual projects.

Road map

Here are some of the features I like to implement at some point.

  • Support the "-npa" option in XJC, suppressing the generation of package level annotations.
  • Support for catalog files.
  • Support for schemas in wsdl files.
  • Support for optionally adding "if-exists" attributes to generated episode files to prevent failures on unreferenced schemas.
  • Document how to register multiple XJC tasks yourself in the same project (for instance for testing only)

You are welcome to create issues and PRs for anything else.

Alternatives

If you need additional functionality than what is provided here, you may want to try the one from unbroken-dome. Just be aware that, at least at the time of this writing, the latest version is 2.0.0, which has some known issues with the jakarta dependencies and the Gradle configuration cache.

xjc-gradle-plugin's People

Contributors

bjornvester avatar nc-bmv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

xjc-gradle-plugin's Issues

Installation question

Downloaded the zip and tred to add plugin from disk. But get:

2023-07-26_13-26-44

Any ideas? IntelliJ IDAE 2023.1.4 (Ultimate Edition)

SourceSets should be configured outside of tasks

As it stands, the XjcPlugin defers adding the java and resource sourceSets until the XjcTask is actually created. This causes some serious problems when trying to use plugins that read and use those sourceSets.

A big example of this is the gradle kotlin plugin, which expects the sourceSets to be stably set when the compile tasks are called. There's no guarantee of this because the XjcTask will configure the sourceSet at some arbitrarily unknown time in the future. As a result, references from Kotlin code to the generated Java code will result in Unresolved reference errors.

I expected this to work:

tasks.named("compileKotlin") {
    dependsOn("xjc")
}

But it seems this still causes the sourceSet to be configured too late.

Along with weird race conditions, it's possible to have concurrent modification exceptions:

sourceSets.main {
    java.srcDir(tasks.named<XjcTask>("xjc").map { it.outputJavaDir })
}

Will throw concurrent modification exceptions because the srcDir is set from both the sourceSets block and the deferred task creation.

A good solution here is to just configure the sourceSet in an afterEvaluate block (outside of the task body). Extensions are fully populated in an afterEvaluate block, and this block will always run before any task is executed or added as long as it's in Plugin.apply.

For now, a simple workaround is just to eagerly create the xjc task:

val xjc by tasks.getting {}

[Q] Is it possible to not run task as part of process resources / compile Java?

Is it possible to disable always running the task as part of process resources / compile Java?

I'm generating the classes from xsd to a dir in buildSrc and they are used by a custom plugin..
I'm also storing the generated classes in source control.
I don't want the classes to be generated if I build the project..

Issues when changing from Java17 to Java21

I use the plugin for creating JAXB classes for an Austrian standard (ร–NORM) which worked fine so far.

After upgrading the Java runtime from Java17 to Java21 I see a new issue popping up.

* What went wrong:
Execution failed for task ':jre'.
> Cannot cast object '[/at/oenorm/schema/a2063/_2009_06_01/AekKenndatenType.class]' with class 'java.util.ArrayList' to class 'java.lang.Void' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.lang.Void(String)

Attached the XSD set.
XSDs.zip

It is also interesting to see that it works fine with
gradle run
and fails for
gradle jpackage

As said, the only difference is the Java runtime used.

A simple test project can be found here: https://github.com/danielpeintner/Java11Test/tree/non-modular

Note: Using the Java21 and downgrading to 17 in my Gradle project solves the problem also!? Any ideas what is happening?

compileJava {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

`outputJavaDir` and `defaultPackage` don't propagate correctly to groups

For a configuration like:

xjc {
  xjcVersion.set "3.0.2"
  useJakarta.set true
  xsdDir.set file("src/main/resources/xsd")
  outputJavaDir.set file("src/model/java")

  groups {
    register("Thing") {
      includes.add "Thing.xsd"
      defaultPackage.set "com.stuff.messages"
    }
    register("In") {
      includes.add "In.xsd"
      defaultPackage.set "com.stuff.messages.in"
    }
  }
}

I would expect the generates files to appear in src/model/java/com/stuff/messages and src/model/java/com/stuff/messages/in. However, instead they land under build/generated/sources/xjc-<group-name>. Notably, they have the correct file structure inside that directory, including correct package declarations set from defaultPackage.

If I add outputJavaDir.set file("src/model/java") to each group (without removing the one set outside groups) , then all files get dumped in src/model/java/com/stuff/messages (even ones that should be in the deeper in/ folder, and package declarations are all set to com.stuff.messages. Notably, the printed paths for each generated class are correct, and show the extended com/stuff/messages/in/Class.java path.

If I further specify the actual package path in each group, like outputJavaDir.set file("src/model/java/com/stuff/messages/in") for the in group, then the same thing happens as before -- package declarations are still all com.stuff.messages, but now all files are dumped in src/model/java/com/stuff/messages/com/stuff/messages (note the repeated package structure).

The example here is a bit simplified, but I think the issues primarily come from the fact that the destination packages and/or folders are nested in each other, and so creation (and deletion) order matters -- for instance, if the In group starts generating first, deleting src/model/java/com/stuff/messages/in and then proceeding to start populating it (which I did see happen, some of the deeper packages would get their directories created, but then would end up being destroyed), but then com.stuff.messages starts generating and deletes src/model/java/com/stuff/messages, we'd run into a problem. What's weird is it does seem like all the types are generated in the final folder (although that may not be the case, it's hard to tell from what I'm running), which means something more complicated is going on.

I ended up just having them all generate in the correct structure under build, and copying them to where I needed the source code to be.

Support generation of multiple schemas within it's own namespace

Would be nice if there is a way to configure settings per schema, as well as for a group of them.

Something along these lines:

xjc {
  schemas {
    firstSet {
      defaultPackage = "tld.domain.first"
      markGenerated = true
      xsdDir = project.file("${project.rootDir}/assets/schemas/first/")
    }
    secondSet {
      defaultPackage = "tld.domain.second"
      markGenerated = true
      xsdDir = project.file("${project.rootDir}/assets/schemas/second/")
    }
  } 
}

In that way, it would be possible to use Different package names/identifiers for a given "set". I think that would be a key piece for this plugin.

Documentation: xsdFiles not supported

The README section about which files to generate schemas for is outdated, i.e. it refers to the xsdFiles. Instead, this should probably be migrated to the includes property.

Premature end of file / HTTPS problems

When trying to XJC the following XSD https://docs.oasis-open.org/ebxml-msg/ebms/v3.0/core/os/ebms-header-3_0-200704.xsd I get his error:

Caught fatal error exception from XJC
org.xml.sax.SAXParseException; systemId: http://www.w3.org/2001/xml.xsd; lineNumber: 1; columnNumber: 1; Premature end of file.
Premature end of file.

Opening the link http://www.w3.org/2001/xml.xsd takes me to https://www.w3.org/2001/xml.xsd, and changing the schema location resolves the error.
However it won't fully compile as I suspect some underlying XSDs use the same reference.

In short I suspect the package has problems handling http links that should be opened in https.

Stackoverflow when using groups without defining xjcVersion

If xjcVersion.set("2.3.3") (or 3.0.0) is omitted when using groups to define multiple schema generations, the gradle build fails mysteriously with:

java.lang.StackOverflowError
        at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
        at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
        at org.gradle.api.internal.provider.AbstractProperty.getProducer(AbstractProperty.java:178)
(and so on...)

This should not be the case as the documentation says: "It has been tested with XJC version 2.3.3 and 3.0.0 (from Jakarta EE). Defaults to 2.3.3."

Example something like this:

groups {
        markGenerated.set(true)
        register("MyXJC") {
            xsdDir.set(layout.projectDirectory.dir("src/main/resources/jaxb"))
            defaultPackage.set("com.something.foobar")
            xsdFiles = project.files(xsdDir.file("Something.xsd"))
            outputJavaDir.set(layout.projectDirectory.dir("src/generated/java/xjc/"))
        }
 }

Tested with xjc-gradle-plugin 1.6.0.

As a personal anectode because of this I tried to create alternative way to configure multiple tasks which have independent xjc definitions but that failed as it seems that the last configuration of xjc was solely picked.

Java class generation fails with java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory, when xjcVersion is set to 3.0.0

My build.gradle is like this:
...
...
xjc {
xjcVersion.set("3.0.0")
xsdDir.set(layout.projectDirectory.dir("src/main/resources/xsd"))
defaultPackage.set("com.xx.xxx.xxxx.model")
}

$ ./gradlew xjc --info

_*** What went wrong:
Execution failed for task ':integration:lib:restvalidation:validationManager:xjc'.

A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]**_

I am using 1.5.1 version.
classpath group: 'gradle.plugin.com.github.bjornvester', name:'xjc-gradle-plugin', version: '1.5.1'

The reason I want to use 3.0.0 version as I want to generate classes with jakarta imports.

If I don't use xjcVersion, then i don't see any issue but it creates files with javax.xml.bind.* and it's not compatible with other part of the code.
Can you please suggest why is it failing and is there anything else I need to do?

Command: C:\Java\java-11-openjdk-11.0.11.9-1.windows.redhat.x86_64\bin\java.exe --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx3072m -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\xxxx.gradle\wrapper\dists\gradle-7.1-all\1esmmb218muptbc8q7pychb8t\gradle-7.1\lib\gradle-launcher-7.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.1

How to generate JAXBELement(String)

JAXB/XJC generates String rather than JAXBElement<String>. How to generate JAXBElement<String> ?
<xs:element name="aerodromePrevious" type="xs:string" minOccurs="0" maxOccurs="1" nillable="true" />

xjc { options = ["-extension", "-Xnamespace-prefix", "-Xdefault-value"] xsdDir.set(layout.projectDirectory.dir("schemas/core")) includes = ["Test.xsd"] bindingFiles.setFrom(layout.projectDirectory.dir("binding").asFileTree.matching { include("**/*.xjb") }) }

Configure language for JavaDoc generation

Hi, i'm missing an option to specify the language code or locale to use when invoking XJC. The current behavior is that environment variable LANG decides which language is selected for generating the JavaDoc comments in the generated files. I would like to have this reproducible, so I'd like a way to define the language on my own.

You currently use
// Set encoding (work-around for https://github.com/gradle/gradle/issues/13843) forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8")
which basically passes the LANG envionment variable down to the XJC worker. But unfortunately LANG is nothing you can control from within a gradle build script or the gradle.properties file. The environment variable can only be set outside of the gradle script, i.e. its value depends on the environment found when the script runs.

My suggestion is to provide a "language" or "locale" option in the XJCExtension that is honored in the forkOptions code above.

I'm using Gradle 8.5 by the way.

Kind regards
Henning

bindingFiles property is not working

bindingFiles property is always empty in https://github.com/bjornvester/xjc-gradle-plugin/blob/master/src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt

Example configuration:
xjc { xsdDir = file("${projectDir}/src/main/resources/") bindingFiles = files("${projectDir}/src/main/resources/my-bindings.xjb") }

I fixed this locally by setting the bindingFiles property again in fun doCodeGeneration():
bindingFiles = getXjcExtension().bindingFiles
Also changed class member bindingFiles from val to var for my test.

Set encoding of generated files

I'm using your plugin on a Windows machine.
I want the generated Java files to be UTF-8 encoded.
However, they turn out to be Windows-1252 (the default encoding on my machine).

I tried to force UTF-8 encoding via the options block. See the following example.
Unfortunately this isn't working.

How can I change the encoding?

xjc {
    xjcVersion = "2.3.3"
    outputJavaDir = file("$buildDir/generated/java")
    outputResourcesDir = file("$buildDir/generated/resources")
    xsdDir = file("src/xsd")
    xsdFiles = fileTree(dir: xsdDir, include: ['*.xsd'])

    options = [
            '-encoding', 'UTF-8']
}

Quiet build is not actually quiet

While the xjc processing is quiet when the flag is set, the call to JCodeModel.build() spits out the name of every generated file it builds to System.out.

It would be preferred to be fully quiet.

Lack of ability to change name of episode file

Currently there is no way to change the output episode file name from sun-jaxb.episode. This create issues when you try and include the output jobs in Android apps because the merger detects the conflict and can't resolve it. There should be a way to rename the episode.

Fluent API options

Hi, I have inherited an old project and have been tasked with upgrading everything at once. It is kind of a nightmare and I don't know a whole lot about all this anyway. One of the upgrades is going from Ant to Gradle and from Java 8 to Java 15 and updating Jaxb to 3.0 as well.

Of all the gradle jaxb plugins I found, this one seemed the best so I went with it. Got everything generating pretty well but it is not quite the same as it used to be. So I was hoping maybe I could get some help on this.

The previous ant target to build looked like this:

    <target name="gen-jaxb" depends="init,clean-gen-jaxb" 
        description="Generates Java classes from the XSD definitions">
        <taskdef name="xjc" classname="com.sun.tools.xjc.XJC2Task">
            <classpath>
                <fileset id="xjc" dir="${deps.dir}/jaxb-xjc" includes="**/*.jar" />
            </classpath>
            <classpath path="${project.buildpath}" />
        </taskdef>
        <xjc destdir="${src}">
            <binding file="bindings.xml"/>
            <schema dir="schemas" includes="**/*.xsd" />
            <arg value="-verbose"/>
            <arg value="-npa"/>
            <arg value="-extension"/>
            <arg value="-Xinject-code"/>
            <arg value="-Xfluent-api"/>
            <arg value="-Xcommons-lang"/>
            <arg value="-Xannotate"/>
        </xjc>
    </target>

I have translated that to this:

plugins {
  id "com.github.bjornvester.xjc" version "1.5.0"
}
dependencies {
  xjc "org.glassfish.jaxb:jaxb-runtime:3.0.0"
  xjc "org.glassfish.jaxb:jaxb-xjc:3.0.0"
}
xjc {
  xjcVersion.set("3.0.0")
  xsdDir.set(file("schemas"))
  outputJavaDir.set(file("src/main/xjc"))
  options.add("-verbose")
  options.add("-npa")
  options.add("-extension")
  options.add("-Xinject-code")
  options.add("-Xfluent-api")
  options.add("-Xcommons-lang")
  options.add("-Xannotate")
}

The first error I've run into for the actual build is the lack of a fluent API. So I'm guessing that I am doing the args wrong in this gradle plugin. I read that options was for 3rd party plugins. So I wasn't sure this would just work anyway. But gave it a shot.

So I guess my question is. How would I translate the args from the ant target to this gradle plugin?

Is it even possible? Or are those only Jaxb 2 options? Or do I need an additional gradle plugin?

I've been working on this about 15 hours straight now so thought I'd stop trying things and ask. :D

Any help is greatly appreciated! :) Thank you.

The plugin fails with Gradle configuration cache enabled

There is a new Gradle feature - configuration caching: https://docs.gradle.org/current/userguide/configuration_cache.html
This plugin is not compatible with it and fails if the caching feature is enabled.

The following error is printed:

* What went wrong:
Some problems were found with the configuration of task ':broker-model:xjc' (type 'XjcTask').
  - Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcBindConfiguration' doesn't have a configured value.
    
    Reason: This property isn't marked as optional and no value has been configured.
    
    Possible solutions:
      1. Assign a value to 'xjcBindConfiguration'.
      2. Mark property 'xjcBindConfiguration' as optional.
    
    Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.
  - Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcConfiguration' doesn't have a configured value.
    
    Reason: This property isn't marked as optional and no value has been configured.
    
    Possible solutions:
      1. Assign a value to 'xjcConfiguration'.
      2. Mark property 'xjcConfiguration' as optional.
    
    Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.
  - Type 'com.github.bjornvester.xjc.XjcTask' property 'xjcPluginsConfiguration' doesn't have a configured value.
    
    Reason: This property isn't marked as optional and no value has been configured.
    
    Possible solutions:
      1. Assign a value to 'xjcPluginsConfiguration'.
      2. Mark property 'xjcPluginsConfiguration' as optional.
    
    Please refer to https://docs.gradle.org/7.1/userguide/validation_problems.html#value_not_set for more details about this problem.

java.lang.NullPointerException when xsd with <jaxb:globalBindings optionalProperty="primitive"> element

Excution failed:

Execution failed for task ':xjc'.
> A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
   > java.lang.NullPointerException (no error message)

When compiling xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://unbroken-dome.org/gradle-xjc-plugin/samples/books"
            xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
            jaxb:version="3.0"
            targetNamespace="http://unbroken-dome.org/gradle-xjc-plugin/samples/books">

  <xsd:annotation>
    <xsd:appinfo>
<!--      <jaxb:globalBindings>-->
      <jaxb:globalBindings optionalProperty="primitive">
        <jaxb:serializable/>
      </jaxb:globalBindings>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:complexType name="bookType">
    <xsd:attribute name="title" type="xsd:string"/>
    <xsd:attribute name="author" type="xsd:string"/>
    <xsd:attribute name="bestseller" type="xsd:boolean"/>
    <xsd:attribute name="publicationYear" type="xsd:gYear"/>
  </xsd:complexType>

  <xsd:element name="book" type="tns:bookType"/>

  <xsd:complexType name="booksType">
    <xsd:sequence>
      <xsd:element ref="tns:book"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="books" type="tns:booksType"/>
</xsd:schema>

build.gradle:

plugins {
  id('java-library')
  id('com.github.bjornvester.xjc') version '1.6.0'
}
repositories {
  mavenCentral()
}

dependencies {
  xjc "org.glassfish.jaxb:jaxb-runtime:3.0.2"
  xjc 'org.glassfish.jaxb:jaxb-xjc:3.0.1'
  xjc 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
  xjc 'jakarta.annotation:jakarta.annotation-api:2.0.0'
  xjc 'jakarta.activation:jakarta.activation-api:2.0.1'
}

xjc {
  xjcVersion.set("3.0.0")
  xsdDir.set(layout.projectDirectory.dir("src/main/schema"))
}

Mixed up binding-files when using groups

Hey,

I'm having trouble with release 1.8.1, because of inconsistent bindings when there is more than one xjc-task involved (which will be the case, when multiple groups are configured). I attached a minimal example-project:

XjcTest.zip

Each group is supposed to generate a single class (A and B).

A has an xsd:dateTime-attribute, which is supposed to be handled via a custom-converter, which is specified in the bindings-file xsd-templates/a/bindings_a.xjb.

B has an xsd:duration-attribute, which is supposed to be handled via another converter, which is specified in the bindings-file xsd-templates/b/bindings_b.xjb.

This example compiles, because it's using the plugin at version 1.8.0. But if you change it to 1.8.1, and replace the lines

bindingFiles = project.files(xsdDir.file("bindings_a.xjb"))

with

bindingFiles.setFrom(project.files(xsdDir.file("bindings_a.xjb"))),

(the same for the B-task respectively)

it will fail.

If we're attempting to run ./gradlew xjcA xjcB --rerun-tasks --info, we see the problem in the output:

> Task :xjcA
Caching disabled for task ':xjcA' because:
  Build cache is disabled
Task ':xjcA' is not up-to-date because:
  Executed with '--rerun-tasks'.
Watching 22 directories to track changes
Watching 21 directories to track changes
Loading XSD files [/home/mz/git/private/XjcTest/xsd-templates/a/A.xsd]
file or directory '/home/mz/git/private/XjcTest/build/xjc/extracted-bind-files', not found
Loading binding files: [/home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb]

> Task :xjcB
Caching disabled for task ':xjcB' because:
  Build cache is disabled
Task ':xjcB' is not up-to-date because:
  Executed with '--rerun-tasks'.
Watching 16 directories to track changes
Watching 15 directories to track changes
Loading XSD files [/home/mz/git/private/XjcTest/xsd-templates/b/B.xsd]
file or directory '/home/mz/git/private/XjcTest/build/xjc/extracted-bind-files', not found
Loading binding files: [/home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb]

Note, that the task xjcA now loads the binding-file /home/mz/git/private/XjcTest/xsd-templates/b/bindings_b.xjb, which means that the code from Main.java will lead to compile errors. Either a.setMyDateTime(OffsetDateTime.MAX); or b.setMyDuration(Duration.ofSeconds(4)); will produce an error, because one of the task will have worked with mismatched binding-file.

I'm guessing, that replacing the FileCollection with ConfigurableFileCollection and making them final has something to do with the problem, but I'm not well versed in the intricacies of gradle. I would appreciate it, if you could have a look.

ClassNotFound exception

I tried to use this plugin on java 11, but I get exception:

* What went wrong:
Execution failed for task ':libs:ndk-em-app-mods:xjc'.
> A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
   > javax/xml/bind/JAXBException

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':libs:ndk-em-app-mods:xjc'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
    at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.github.bjornvester.xjc.XjcWorker
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkerExecution.waitForCompletion(DefaultWorkerExecutor.java:285)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:115)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.access$000(DefaultAsyncWorkTracker.java:34)
    at org.gradle.internal.work.DefaultAsyncWorkTracker$2.run(DefaultAsyncWorkTracker.java:83)
    at org.gradle.internal.Factories$1.create(Factories.java:25)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:254)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:165)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withoutProjectLock(DefaultWorkerLeaseService.java:159)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withoutProjectLock(StopShieldingWorkerLeaseService.java:90)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:79)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:412)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:393)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:376)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:213)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:201)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:77)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
    ... 35 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getCustomizationContext(BindInfo.java:306)
    at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getCustomizationUnmarshaller(BindInfo.java:332)
    at com.sun.tools.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl$1.<init>(AnnotationParserFactoryImpl.java:55)
    at com.sun.tools.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl.create(AnnotationParserFactoryImpl.java:54)
    at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.createAnnotationParser(NGCCRuntimeEx.java:371)
    at com.sun.xml.xsom.impl.parser.state.annotation.action0(annotation.java:59)
    at com.sun.xml.xsom.impl.parser.state.annotation.enterElement(annotation.java:84)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.NGCCHandler.spawnChildFromEnterElement(NGCCHandler.java:84)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:287)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.NGCCHandler.revertToParentFromEnterElement(NGCCHandler.java:121)
    at com.sun.xml.xsom.impl.parser.state.foreignAttributes.enterElement(foreignAttributes.java:61)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.NGCCHandler.spawnChildFromEnterElement(NGCCHandler.java:84)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:199)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:243)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:279)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:267)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:191)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.sendEnterElement(NGCCRuntime.java:392)
    at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:227)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:233)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:78)
    at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:120)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:98)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:163)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.ModelLoader$SpeculationChecker.startElement(ModelLoader.java:414)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.internalizer.VersionChecker.startElement(VersionChecker.java:73)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
    at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:70)
    at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:438)
    at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:210)
    at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:351)
    at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:258)
    at com.sun.xml.xsom.impl.parser.state.importDecl.action0(importDecl.java:56)
    at com.sun.xml.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:167)
    at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:289)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at com.sun.tools.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:82)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:169)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
    at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:70)
    at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:438)
    at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:210)
    at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:351)
    at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:98)
    at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:141)
    at com.sun.tools.xjc.ModelLoader.createXSOMSpeculative(ModelLoader.java:455)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:310)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:121)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:76)
    at com.github.bjornvester.xjc.XjcWorker.run(XjcWorker.kt:27)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:39)
    at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$WorkerCallable.call(IsolatedClassloaderWorkerFactory.java:165)
    at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.executeInWorkerClassLoader(IsolatedClassloaderWorkerFactory.java:93)
    at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.access$000(IsolatedClassloaderWorkerFactory.java:53)
    at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1$1.execute(IsolatedClassloaderWorkerFactory.java:72)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1.execute(IsolatedClassloaderWorkerFactory.java:69)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:105)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:99)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    ... 3 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
    ... 111 more

Add an option to change the source set of the generated code

Currently the default xjc task is created and its output is added to the main SourceSet.

I have a project that only generates code for the test SourceSet. Ideally I would like the ability to switch the source set of the generated code.

It seems like the main SourceSet is being hard-coded to be added to here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.