X

Geertjan's Blog

  • September 2, 2014

Lombok, Maven, and NetBeans

Geertjan Wielenga
Product Manager

Here's a POM that incorporates Lombok:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>BookManager</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

For adding the Lombok dependency above, you're able to add the @Data annotation from Lombok. The Navigator in NetBeans automatically shows all the getters and setters made available by Lombok, which you don't need to code and maintain yourself because they're not in your code. Click to enlarge the image below.

Now you can use all those getters and setters without ever having coded them, for example:

public class Main {

    public static void main(String[] args) {
        MyBooks mb = new MyBooks(1850, "Tale of Two Cities", "Dickens");
        String title = mb.getTitle();
        String author = mb.getAuthor();
        int year = mb.getYear();
        System.out.println("title = " + title);
        System.out.println("author = " + author);
        System.out.println("year = " + year);
    }

}

Use code completion in the version element of the POM to check what the latest Lombok JAR version is:

In the Services window, you can explore the Maven repo:

In "Local" above, after building the project which downloads the dependencies you've declared, you'll find the Lombok JAR declared in the POM:

In "Central Repository", you'll find all the Lombok JARs, which explains the code completion results, i.e., that's where they come from:


Simple, smooth, intuitive integration of Maven, and from Maven to Lombok, in NetBeans IDE.

Join the discussion

Comments ( 12 )
  • guest Wednesday, September 3, 2014

    some experimental features aren't work in NetBeans, but anyway good thing


  • Geertjan Thursday, September 4, 2014

    Which experimental features are you talking about? I don't believe NetBeans has any experimental features, so I'm curious to know what you're talking about.


  • guest Thursday, September 4, 2014

    I have forgotten what exactly didn't work (compile error in ide editor) cause I have been testing Lombok a year ago, but it's likely was from page

    http://projectlombok.org/features/experimental/index.html

    some annotations worked well despite documentation awareness, but one or two was really unusable.


  • Geertjan Saturday, September 6, 2014

    Well, completely impossible to help you with the description you've provided so far. Let me know when you have something that can be reproduced today, i.e., not something random you did last year.


  • Mehul Boricha Sunday, September 28, 2014

    Thanks.


  • Morten Christensen Wednesday, October 22, 2014

    I also looked at Project Lombok but deemed it too risky to use (f.x. there are issues with the latest JDK). I also found the customisation features lacking, so I just released my own open source tool for generating java value objects (with getters, setters, constructors, equals, hash, compareTo and more) that used 100% standard java features, integrates with all java tools and is extremely customisable. You can check it out at "http://valjogen.41concepts.com". Let me know what you think?


  • guest Thursday, June 9, 2016

    I love to use lombok on netbeans (my favorite IDE). But the ExtensionsMethod feature do not have auto-complete on Netbeans. It make my partner must take a time to look for my function in Extension.class.

    Hope, it will work soon.


  • Rahul khandelwal Friday, June 17, 2016

    Hi Geertjan, I am trying to use lombok in netbeans 8.2 nightly build (17th june 2016). But I can't find the option of Enabling Annotation Processing in maven project. could you help with that ?


  • guest Tuesday, October 4, 2016

    Hi Geertjan, I hate to piggy back on Rahul Khandelwal post, but I too am trying to use NB 8.2 and seems that Lombok is not working as well..err...I am trying to enable Annotation Processing for gradle and don't seem to be able to find the right spot. Thanks in advance for you response.


  • Geertjan Tuesday, October 4, 2016

    Can't help without any clues. Just follow the steps in this blog entry, read from the top of the page, i.e., include the Maven plugin etc.


  • guest Wednesday, October 19, 2016

    I had the same issue while updating to 8.2 (getters and setters not visible by Netbeans) and ended up on this post too.

    Solution for me: I removed the specific version number in the maven dependency (removed the <version>....) and it works fine right away.

    I hope this helps.


  • Gerrick Thursday, December 1, 2016

    Yikes...Lombok integration seems broken with NetBeans 8.2...

    Specifically if I create a NetBeans RCP application with Maven,

    a simple class like this:

    //Navigator doesn't show the generated

    // method getCounter()

    @Data

    public class TestLombok

    {

    private int counter;

    }

    and the following attempt to reference it:

    public class TestUseClass

    {

    public void test(TestLombok tl)

    {

    int cntr = tl.getCounter(); //<== red badges in IDE

    }

    }

    shows errors in the IDE when trying to reference the methods that should

    be generated. The Navigator also doesn't show the methods.

    Compilation is fine so it seems like and issue with the UI


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services