IllegalStateException in Hibernate metamodel generation with maven

Found the Answer!...

It's a bug in 3.2 & 3.3 versions of maven-compiler-plugin.

When I run the 'mvn package' second time, the previously generated source directory is added to the source path before the generate-source phase and it causes this parser exception.

Switching back to the older version (<3.2) of maven-compiler-plugin fixes the issue.

Note that the incremental compilation is broken in 3.0 & 3.1 versions of maven-compiler-plugin. So, I prefer to switch the 2.5.1 version of maven-compiler-plugin.

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
</dependency>

Same issue faced with gradle build as well. If you have previously metamodel classes available @ source-generate(please check the build.gradle file to check the path where your model classes being generated), this issue will come when run gradle build.

Solution : Delete the existing model classes and run gradle build. It should workout.


This bug is fixed in the meantime. You should use maven compiler plugin 3.6 or higher:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0</version>
</dependency>