Tuesday, February 5, 2019

Maven: use lombok combined with OpenJPA metadata generation

Here is a example how to use lombok combined with OpenJPA metadata generation inside the maven-compiler-plugin:
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.0</version>
        </dependency>

        <!-- needs to be defined here for the annotation processor -->
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa</artifactId>
            <version>3.0.0</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                        <annotationProcessors>
                            <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
                            <annotationProcessor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</annotationProcessor>
                        </annotationProcessors>
                        <compilerArgs>
                            <arg>-Aopenjpa.metamodel=true</arg>
                            <arg>-Aopenjpa.source=7</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>