Search code examples
jpajhipstermetamodelmaven-compiler-pluginjava-10

JHipster5 project with JPA static metamodel on Java 10


I have been trying to upgrade my JHipster 5 application to use Java 10 but I can't get it to compile and process JPA static metamodels with Maven.

Apparently maven-compiler-plugin is not triggering hibernate-jpamodelgen in order to generate the JPA static metamodels.

In order to upgrade the project I have:

  • installed Oracle´s JDK 10.0.1
  • switched my pom.xml to <java.version>10</java.version>
  • upgraded maven-compiler-plugin to add java.xml.bind module (since it is not included by default as of Java 10) as follows:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <!-- fork is needed so compiler args can be used -->
                <fork>true</fork>
                <compilerArgs>
                    <arg>-J--add-modules</arg>
                    <arg>-Jjava.xml.bind</arg>
                </compilerArgs>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </path>
                    <!-- For JPA static metamodel generation -->
                    <path>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-jpamodelgen</artifactId>
                        <version>${hibernate.version}</version>
                    </path>
    
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    

With this I am getting compilation failure when I run ./mvnw clean compile with no further detailed error message.

If I remove the <compilerArgs> tag from pom.xml and run the same command I get: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

I have followed the upgrade instructions provided here

Also, I made this example project available on GitHub

This is the commit changes where I upgraded to Java 10


Solution

  • In order to register the solution here wishing to help others, here is what solved this issue:

    It turns out it was some Java 9 compatibility problem with [email protected]. Once I upgraded to Hibernate version 5.3.1.Final it started to compile again.

    I also had to solve JAXB dependencies following this answer.