This project packages the annotations of Project Lombok as separate JAR to improve compiling and handling Java sources generated by Delombok.
Changelog | JavaDoc | Generated Reports
Lombok Annotations are meant to be used in conjunction with Delombok and without Project Lombok.
<dependency>
<groupId>de.lars-sh</groupId>
<artifactId>lombok-annotations</artifactId>
<version><!-- TODO --></version>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version><!-- TODO --></version>
<executions>
<execution>
<goals>
<goal>delombok</goal>
<goal>testDelombok</goal>
</goals>
</execution>
</executions>
</plugin>
Project Lombok can be used by adding its dependency at compile time.
Here's how the Maven dependency looks like:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version><!-- TODO --></version>
<scope>provided</scope>
</dependency>
The Java sources compiled differ from your sources and highly depend on Project Lomboks version and magic.
Though you might need the correct Java sources. For yourself to understand what's going on, for debugging purposes, for documentation or even for revision control.
Therefore keep your Maven dependency and add the Lombok Maven Plugin to execute Delombok on your sources.
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version><!-- TODO --></version>
<executions>
<execution>
<goals>
<goal>delombok</goal>
<goal>testDelombok</goal>
</goals>
</execution>
</executions>
</plugin>
The plugin runs Delombok on your sources, places the resulting Java sources at target/generated-sources/delombok
and tells Maven to compile those.
No! The Lombok Maven Plugin is alright, but as Project Lombok is still part of your dependencies, it registers itself when compiling and processes the generated sources a second time.
That reduces compiling performance and might modify your sources even further. Take a look at demos/demo-2-delombok-and-lombok
as an example:
- Run "mvn package". The build process fails. Don't hesitate, that's the correct behavior!
- Delombok was executed just as expected. You can verify this yourself.
- Even though the compilation fails, as
demoField
is missing the@NonFinal
annotation.
Note: This demo makes use of lombok.fieldDefaults.defaultFinal=true
inside lombok.config
.
Therefore simply replace the dependency to Project Lombok with the one for Lombok Annotations as done at Getting started. No magic, no more than that.
Using Lombok Annotations does not load Project Lomboks logic implicitly, while the Lombok Maven Plugin / Delombok and the Eclipse plugin still do their work as expected.