JPA Metamodel Generation with Java 11 and Error Prone


#1

The last hurdle that I’m running into with my migration to Java 11 is getting the Hibernate JPA Metamodel generation to run alongside Google’s error-prone static analysis.

Their configuration above Java 8 requires that you define it as an annotation processor path in the maven complier plugin. http://errorprone.info/docs/installation

Once you add something to the annotation processor paths they are no longer discovered dynamically so I have to move the hibernate-jpamodelgen into the annotation processor paths as well.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>11</source>
        <target>11</target>
        <compilerArgs>
            <arg>-XDcompilePolicy=simple</arg>
            <arg>-Xplugin:ErrorProne</arg>
        </compilerArgs>
        <annotationProcessorPaths>
            <path>
                <groupId>com.google.errorprone</groupId>
                <artifactId>error_prone_core</artifactId>
                <version>2.3.3</version>
            </path>
            <path>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>5.3.9.Final</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

When I do that however the build fails.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project oss: Fatal error compiling: java.lang.NoClassDefFoundError:javax/xml/bind/JAXBException: javax.xml.bind.JAXBException -> [Help 1]

It would appear that the hibernate-jpamodelgen is missing a dep to the jax-b libraries which are no longer included in Java 11.

Has anyone else run into this?


#2

I did find a workaround posted @ https://hibernate.atlassian.net/browse/HHH-12991 but I’m still unable to get that to build successfully.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>11</source>
        <target>11</target>
        <compilerArgs>
            <arg>-XDcompilePolicy=simple</arg>
            <arg>-Xplugin:ErrorProne</arg>
        </compilerArgs>
        <annotationProcessorPaths>
            <path>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>5.3.9.Final</version>
            </path>
            <path>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.0</version>
            </path>
            <path>
                <groupId>javax.annotation</groupId>
                <artifactId>javax.annotation-api</artifactId>
                <version>1.3.1</version>
            </path>
            <path>
                <groupId>com.google.errorprone</groupId>
                <artifactId>error_prone_core</artifactId>
                <version>2.3.3</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

#3

Open Jira issue for this as it looks like a bug. While at it, try to provide a fix as well.


#4

@vlad

JIRA is https://hibernate.atlassian.net/browse/HHH-12991

Unfortunately I don’t have any background in gradle so I’m a little lost as to modifying the dependencies.