Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cohexist lombok and JPAMetalModel processors with maven

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.

like image 766
Pierrick Avatar asked Aug 04 '15 09:08

Pierrick


People also ask

What is annotationProcessorPaths in maven?

<annotationProcessorPaths>The detection itself depends on the configuration of annotationProcessors. Each classpath element is specified using their Maven coordinates (groupId, artifactId, version, classifier, type). Transitive dependencies are added automatically.

How do I add Lombok to my pom?

Adding the Lombok Plugin in IDE (Eclipse) Downloaded jar from https://projectlombok.org/download or use the jar which is downloaded from your maven build. Execute command in terminal: java -jar lombok. jar. This command will open window as show in the picture below, install and quit the installer and restart eclipse.

What is maven processor plugin?

A maven plugin to process annotation for jdk6 at compile time This plugin helps to use from maven the new annotation processing provided by JDK6 integrated in java compiler This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.codehaus.org/apt-maven-plugin/

What is Lombok dependency?

To set up lombok with any build tool, you have to specify that the lombok dependency is required to compile your source code, but does not need to be present when running/testing/jarring/otherwise deploying your code. Generally this is called a 'provided' dependency.


1 Answers

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>
[...]
like image 159
Pierrick Avatar answered Sep 28 '22 01:09

Pierrick