Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit tests fail with Java error when using IntelliJ within maven module after adding Hibernate Metamodel classes

On my project we've used Hibernate's (JPA) Metamodel Generator to make our Criteria queries type safe. It all works great within our app, however, when we run the JUnit tests within that Maven module using our IDE they now fail with the following error:-

Error:java: Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found

Which I guess is due to the following in our generated classes:-

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor") @StaticMetamodel(MyEntity.class)

When Maven runs the tests as part of our build process then they run with no problems at all.

I suspect I'm missing something within the set up of my IDE, which is IntelliJ IDEA 14. Any ideas what this might be? Or have I done something wrong within Maven? :-

   <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>2.1.0</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <processors>
                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                        </processors>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-jpamodelgen</artifactId>
                    <version>4.3.4.Final</version>
                    <optional>true</optional>
                </dependency>
            </dependencies>
        </plugin>
like image 250
Sausage Avatar asked Dec 05 '22 23:12

Sausage


1 Answers

I had a similar problem after I upgraded to IntelliJ IDEA 14.1.2. For me the following action resolved the problem:

Go to Settings > Build, Execution, Deployment > Compiler > Annotation Processors.

On the left of this configuration panel I have an Annotation profile for every maven module in my project. I did not set up these profiles myself: maybe they where inferred by the IDE. I don't know, but in some of these annotation profiles, the enable annotation processing flag was enabled. Moreover, in some cases, the JPAMetaModelEntityProcessor was explicitly listed here as an annotation processor. After removing the annotation processor from the profile and disabling the checkbox, the error disappeared and my test ran successfully.

like image 79
Jeroen Noels Avatar answered Dec 11 '22 09:12

Jeroen Noels