问题描述
如果在maven版本中激活JPAMetaModelEntityProcessor注释处理器,如何使用。
How to use Lombok when JPAMetaModelEntityProcessor annotation processor is activated in the maven build.
Maven config:
Maven config:
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
[...]
在构建过程中(mvn clean install),MetaModel对象生成正确,但似乎Lombok Annotation处理器不再添加到Javac编译中。所有@Getter,@ Setter,......都不起作用。
During the build process (mvn clean install), MetaModel objects are generated correctly but it seems the Lombok Annotation processor is not added into the Javac compilation anymore. All @Getter, @Setter,... doesn't work.
推荐答案
在查看lombok项目后,我找到了一个解决方案。
After a look into the lombok project I found a solution.
当将JPAMetaModelEntityProcessor指定为javac注释处理器时,似乎删除了lombok处理器。
When specifying the JPAMetaModelEntityProcessor as javac annotation processor, the lombok processor seems to be removed.
To更正这一点,我们可以简单地在maven-compiler-plugin中添加Lombok注释处理器:
To correct this, we can simply add the Lombok annotation processor in the maven-compiler-plugin:
[...]
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
[...]
这篇关于如何使用maven协调lombok和JPAMetalModel处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!