How to cohexist lombok and JPAMetalModel processors with maven

不羁岁月 提交于 2019-12-21 09:28:39

问题


How to use Lombok when JPAMetaModelEntityProcessor annotation processor is activated in the maven build.

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>
[...]

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.


回答1:


After a look into the lombok project I found a solution.

When specifying the JPAMetaModelEntityProcessor as javac annotation processor, the lombok processor seems to be removed.

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>
[...]



回答2:


The solution of @Pierrick is right. but I can offer this solution. because we can add many processors with this.

<plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
      <annotationProcessorPaths>
         <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
         </path>
         <path>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-jpamodelgen</artifactId>
             <version>5.4.1.Final</version>
         </path>
      </annotationProcessorPaths>
   </configuration>
</plugin>



回答3:


The Solution if @Pierrick is not totally correct. You have to switch the order of the processors.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArguments>
            <processor>
                lombok.launch.AnnotationProcessorHider$AnnotationProcessor,org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
            </processor>
        </compilerArguments>
    </configuration>
</plugin>


来源:https://stackoverflow.com/questions/31805327/how-to-cohexist-lombok-and-jpametalmodel-processors-with-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!