How to ignore the Java Source directory during Maven Compilation?
java, lombok, maven
Solution
I recently switched from using the flakey maven-exec-plugin approach to generate raw sources for the javadoc tool to using lombok-maven-plugin
My setup
- All sources in `src/main/java`
- Generated sources go in `target/generated-sources/delombok`
I initially ran into this problem but it seems to be an easy fix: Don't let lombok-maven-plugin add the delombok path to the compiler source paths with `addOutputDirectoy`. IE
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>0.11.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<configuration>
<addOutputDirectory>false</addOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
</configuration>
</plugin>
This seems to of solved the issue for now
EDIT: Bonus, how to generate proper javadocs with this setup
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<defaultVersion>${project.version}</defaultVersion>
<sourcepath>target/generated-sources/delombok</sourcepath>
</configuration>
</plugin>
Problem
I am trying to use the Lombok Maven Plugin to ensure the correct creation of Javadocs when using Lombok. Lombok Maven introduces a new code generation goal, just prior to compilation. In my configuration, my `sourceDirectory` (Java with Lombok annotations, `src/main/java`) is processed to create Java (without Lombok annotations) in `target/generated-sources/delombok`. However, every file in `sourceDirectory` now has a corresponding (identically named) file in `target/generated-sources/delombok`, resulting in compilation failures due to duplicate classes. How can I tell the Java compiler to ignore the sources in `sourceDirectory`? Note that the default Lombok Maven configuration would have the developer put Java (with Lombok annotations) in the `src/main/lombok` folder instead of `src/main/java`. However, I do not wish to do this because it confuses IDEs and my code compiles just fine (if I remove the Maven plugin). Also note that simply redefining `sourceDirectory` will also upset IDEs (they no longer know where to find the Java source code!).