IntershopCommunicationsAG/jaxb-gradle-plugin

Newer plugin version (5.1.0, 5.0.0, 4.4.2) is not honoring embedded bindings.

Closed this issue · 2 comments

We are upgrading the gradle version so we needed to upgrade the plugin also. Unfortunately the newer plugin version is NOT honoring embeded bindings present in the xsd file. Tried all the newer version but got the same result.
Previously we were on 2.0 plugin version and it honored the embedded bindings. Please suggest what changes I need to make.
Tried it on Java 8 and Java 11, I see the same behavior in both setup.
I used xjc commandline (Java 8) and it honored the embedded binding and didn't create ApiValidator class. (details below)

classpath group: 'com.intershop.gradle.jaxb', name: 'jaxb-gradle-plugin', version: '5.1.0'

build.gradle:

jaxb {
    javaGen {
        name {
            schema = file('src/main/resources/xsd/Validation.xsd')
            packageName = 'a.b.c.d.e.f.g.model'

        }
    }
}

And xsd file is below and embeded binding is ApiValidator. This class is already present and I want to use that.

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="a.b.c.d.e.f.g/model"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
           xmlns:tns="a.b.c.d.e.f.g/model" elementFormDefault="qualified">

    <xs:attribute name="Description" type="xs:string"/>
    <xs:attribute name="Required" type="xs:boolean"/>

    <xs:complexType name="ValidationAction">
        <xs:sequence>
            <xs:element name="api" type="xs:string" tns:Description="Indicates the validation API"/>
            <xs:element name="method" type="xs:string" tns:Description="Indicates the validation method"/>
            <xs:element name="beanName" type="xs:string" tns:Description="Validation bean name"/>
            <xs:element name="validationClass" type="xs:string" tns:Description="Validation class type"/>
            <xs:element name="idOwner" type="xs:int" tns:Description="Indicates the owner associated with the validation"/>
            <xs:element name="valid" type="xs:boolean" tns:Description="Indicates if validation is valid"/>
            <xs:element name="validator" type="_tns:ApiValidator_" minOccurs="0" maxOccurs="1"
                        tns:Description="Reference to the API validator"/>
        </xs:sequence>
    </xs:complexType>
    
    <complexType name="ApiValidator">
        <annotation>
            <appinfo>
                <jaxb:class ref="a.b.c.d.e.f.g.ApiValidator"/>
            </appinfo>
        </annotation>
    </complexType>

Also tried this format:
    <xs:complexType name="ApiValidator">
        <xs:annotation>
            <xs:appinfo>
                <jaxb:bindings node="//xs:complexType[@name='ApiValidator']">
                    <jaxb:class ref="a.b.c.d.e.f.g.ApiValidator"/>
                </jaxb:bindings>
            </xs:appinfo>
        </xs:annotation>
    </xs:complexType>

</xs:schema>

Argeument for javagen: {destdir=C:\GIT_CONTAINER....\target\generated\jaxb\java\name, language=XMLSCHEMA, encoding=UTF-8, header=true, extension=false, fork=true, package=a.b.c.d.e.f.g.model, schema=C:\GIT_CONTAINER...\src\main\resources\xsd\Validation.xsd}

[ant:jaxb] [WARNING] No JAXB customization was detected in the schema but the prefix "jaxb" is used for other namespace URIs. If you did intend to use JAXB customization, make sure the namespace URI is "https://jakarta.ee/xml/ns/jaxb"
[ant:jaxb] unknown location
[ant:jaxb] compiling a schema...
[ant:jaxb] [INFO] generating code
[ant:jaxb] unknown location
[ant:jaxb]
[ant:jaxb] a\b\c\d\e\f\g\model\ApiValidator.java <-------------This is getting created. The ApiValidator class is already present and I want jaxb to use it.
[ant:jaxb] a\b\c\d\e\f\g\model\ObjectFactory.java
[ant:jaxb] a\b\c\d\e\f\g\model\ValidationAction.java
[ant:jaxb] a\b\c\d\e\f\g\model\package-info.java

Downloaded 3.0.0 version from https://eclipse-ee4j.github.io/jaxb-ri/ and ran the xjc.sh and I see the same behavior (ApiValidator.java) is getting created.. so the behavior is consistent. Doesn't seem to be the issue with newer plugin version.
Still not sure, how to let it use embedded bindings?
I will go ahead and cancel this as issue doesn't seem to be plugin related.

Using the xjc.sh command line, found out that the issue was with the jaxb version.
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
The issue went away once I updated the version value to 3.0.0.