在添加Hibernate Metamodel类之后,在maven模块中使用IntelliJ时,JUnit测试失败并出现Java错误

Sau*_*age 4 junit jpa criteria intellij-idea maven

在我的项目中,我们使用了Hibernate(JPA)元模型生成器来使我们的Criteria查询类型安全.这一切都在我们的应用程序中运行良好,但是,当我们使用我们的IDE在Maven模块中运行JUnit测试时,它们现在失败并出现以下错误: -

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

我猜这是由于我们生成的类中的以下内容: -

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

当Maven将测试作为构建过程的一部分运行时,它们运行时完全没有问题.

我怀疑我在IDE的设置中缺少一些东西,这是IntelliJ IDEA 14.任何想法可能是什么?或者我在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>
Run Code Online (Sandbox Code Playgroud)

小智 11

升级到IntelliJ IDEA 14.1.2后,我遇到了类似的问题.对我来说,以下操作解决了这个问题:

转到设置>构建,执行,部署>编译器>注释处理器.

在这个配置面板的左侧,Annotation profile我的项目中的每个maven模块都有一个.我自己没有设置这些配置文件:也许它们是由推断出来的IDE.我不知道,但在其中一些注释配置文件中,启用启用注释处理flag.此外,在某些情况下,JPAMetaModelEntityProcessor在此处明确列为注释处理器.后取出注解处理器从配置和禁用checkbox,错误消失了,我的测试运行成功.