Using Lombok 1.16 with Netbeans 8.1 and Maven

Project Lombok provides annotations which reduce boilerplate code in Java applications (see Listing 1). The Netbeans IDE supports it almost out-of-the-box. You just have to enable the option “Project Properties > Build > Compiling > Enable Annotation Processing”. However the current version 1.16.8 is not working using Netbeans 8.1 and Maven.

Using Lombok Version 1.14 …

If you’re using Lombok 1.14, Netbeans and Maven, everything works find. Just add the following dependency to your pom.xml:

… using Version 1.16…

If you’re not using Maven, everything is still fine! Just add version 1.16 to your project dependencies using “Project Properties > Libraries”. Netbeans uses its default build.xml and your have to manage your project dependencies on your own. Have fun!

Enable Lombok Annotation Processing in Netbeans

Enable Lombok Annotation Processing in Netbeans

One way to avoid this is simply using version 1.14. It provides the very usefull @Getter, @Setter and @Data annotations and a lot of other stuff. One of our customers however uses the @Builder annotation heavily throughout the code. In a plain-old Netbeans project with Ant. So…

  • @Builder is stable since Lombok 1.16
  • It deminishes A LOT of boilerplate code
  • We need to stick to version 1.16

Now a problem occures when I wanted to build the project with Maven (or in Jamaican: “a situation occurs”). Integrating Maven makes of course also a lot of sense if you don’t want to update your Spring dependencies by hand :)

However Maven fails with an error message like this:

Delombok your source code

Delombok takes the annotated classes and replaces them with the actually generated code. This can be useful for Javadoc generation or the integration into the Google Widget Toolkit.

The solution is now to integrate the delombok Maven plugin into the Maven lifecycle:

The delomboked code is then placed in target/generated-sources/delombok.

So when you’re modifying the entities, you have to build your project twice. The first run is delomboking the sources by running maven with lombok:delombok. Then you can use the generated methods:

If you just want to compile an existing project, building once is enough as the plugin runs in the generate-sources phase.

Summary

We got Lombok 1.16 working with Netbeans 8.1 and Maven by simply adding one Maven plugin. Check out the sources of the sample project on Github!

Share on FacebookShare on LinkedInShare on Google+Tweet about this on Twitter

2 thoughts on “Using Lombok 1.16 with Netbeans 8.1 and Maven

  1. Anders

    Hi
    The “enable annotation processing” is only available for the non-Maven projects in my workspace. I am running Netbeans 8.1 on a Macbook pro. Is the option to be found somewhere else for Maven projects?

    Reply
    1. Daniel Wieth Post author

      Hey,
      No, the option does not exist for Maven projects. But for Lombok you don’t need to check such a flag for a Maven project. As long as Lombok is a dependency of your project, the annotations will be processed automatically. Which Version of Lombok are you using?
      Best
      Daniel

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *