Maven, Lombok and Eclipse - semantic integration template

So, I have long wanted to use Lombok - and I am finally starting a project where I can use it. It is important to note that this will be a large enterprise-level application, and therefore the integration patterns used should be meaningful with a minimum number of hackers.

So, I looked at the lombok-maven plugin and the whole delombok fudge. I understand that this duplicates all my code and extends the lombok annotations where they are present. This gives me a second set of generated .java files that maven should use at compile time.

However, by creating these new source files, eclipse selects them and tries to pull them into my project. Thus, it takes millions (OK, slight exaggerations) of errors in relation to repetitive classes.

Some solution assumes that I am changing the <sourceDirectory> in my POM. This makes things no better, since mvn eclipse:eclipse now completely drop my src/main/java directory from the project - it will only show me the result of the delombok process.

Then comes the suggestion that I need to use one profile to compile / package the project, and the other mvn eclipse:eclipse . This is not an acceptable solution, since I have to spend enough time maintaining / explaining my already complicated maven setup - without having to enter an entire new profile (besides my existing profiles).

I hope for some inspiration to save me from recording Lombok for my project. This is a great tool for reducing the code of templates, but it just does not seem ready for use in real time in business, which I consider very disappointing: - (

The following is my POM:

 <build> <sourceDirectory>target/generated-sources/delombok</sourceDirectory> <testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.12.2.0</version> <dependencies> <dependency> <groupId>sun.jdk</groupId> <artifactId>tools</artifactId> <version>1.7</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> </dependencies> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> <configuration> <encoding>UTF-8</encoding> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>src/main/java</sourceDirectory> </configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase> <goals> <goal>testDelombok</goal> </goals> <configuration> <encoding>UTF-8</encoding> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> 

Currently, it only puts deliberated code in my eclipse project.


Final note. I am also very upset that I need to manually install lombok in all the eclipse installations that we are going to use. Mostly because it's me who will receive a phonecall from all developers who cannot make it work. I understand why it is not as simple as mvn eclipse:eclipse , but I still wanted to note my disappointment. If we had to manually configure each library for use on each development machine, we returned to the pre-maven days.

+8
java eclipse maven lombok
source share
2 answers

You do not have to use the lombok-maven-plugin to take advantage of Lombok. As far as I understand, the delombofication that the plugin does is intended to allow things like code coverage and javadoc to have the full version of the code. Even then, the process will occur, for example, during the construction of Javadok.

The question is whether your project can live without it. If so, then just adding a lombock to a Maven dependency is all you need.

In Eclipse you really need to install it. Please note that the fact that Lombok is still experimental is probably due to reasons that it did not include in Eclipse by default.

+5
source share

We have been successfully using lombok in our project for 1.5 years. We do not use delombokification, but instead have a lomb as a provided dependency like

  <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>0.11.0</version> <scope>provided</scope> </dependency> 

That is all that is needed. We can use lombok annotations, and they are recognized by both eclipse and maven. It is even compatible with EclEmma in eclipse, which marks annotations as (un) when the corresponding generated code is (not).

You need to install it on each instance of Eclipse manually, since most JDTs are not open for eclipse plugins to modify. This is a technical limitation that Lombok developers cannot remove. In any case, the installer is quite simple and has never let me down so far.

+7
source share

All Articles