How to cohexist lombok and JPAMetalModel processors with maven

前端 未结 3 915
名媛妹妹
名媛妹妹 2021-02-14 05:27

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

Maven config:

[...]

    

        
相关标签:
3条回答
  • 2021-02-14 05:37

    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>
    
    0 讨论(0)
  • 2021-02-14 05:41

    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>
    
    0 讨论(0)
  • 2021-02-14 05:53

    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>
    [...]
    
    0 讨论(0)
提交回复
热议问题