12

I want to use Lombok in a project to use @Getter and @Setter.

I included using Maven:

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

Import is OK for Netbeans:

import lombok.Getter;
import lombok.Setter;

But auto setters and getters don't work (no autocompletion / "cannot find symbol ...").

Strange thing is that for another project I have it's working fine! But I can't figure the differences.

I tested to:

  • change the lombok version (even the last): for any version, the import don't work anymore

  • build the project with Maven: it's OK!

  • use Eclipse: it's OK! (but I am the only one to decide unfortunately)

=> so I'm sure this is a Netbeans related problem

  • enable annotation processing, as I've seen in tutorials=> I don't have such option in my project properties

enter image description here

Any idea ?

Rolintocour
  • 2,934
  • 4
  • 32
  • 63

4 Answers4

10

In Netbeans 8.2 using Apache Maven 3.5.4 use Lombok 1.18.4 or much older 1.16.16.

In Netbeans 10.0/9.0 using Apache Maven 3.5.4 use Lombok 1.18.4, older versions of Lombok are really buggy when Compile On Save is used in Netbeans 10.0/9.0

I updated Lombok to a new version(The newer the version the better)

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
    <version>1.18.8</version> <!--1.18.8 for Netbeans 9/10 OR 1.16.16 for Netbeans 8 with Java 8 -->
</dependency>

NB

  • For maven-compiler-plugin, remove any annotationProcessorPaths to do with Lombok in the maven-compiler-plugin
  • Remove any Lombok maven plugins

This is not needed, as Maven and Netbeans does this out of the box. You only need the right Lombok dependency in Maven.

rjdkolb
  • 10,377
  • 11
  • 69
  • 89
  • 1
    True, use 1.18.0 in Netbeans 9 RC1. I've added details. It also works in Netbeans 9 VC3 https://dist.apache.org/repos/dist/dev/incubator/netbeans/incubating-netbeans-java/incubating-9.0-vc3 – rjdkolb Jul 11 '18 at 08:44
  • Doesn't work either :( I have cleaned target, settings file, re-imported the project ... – cactuschibre Jul 11 '18 at 09:03
  • 2
    Thanks! It works now, I was using the bundled Maven of Netbeans 9 (3.3.9). I have switched to the latest version (3.5.4) and everything is fine now :) – cactuschibre Jul 11 '18 at 09:42
  • Doesn't work on Netbeans 10.0. Am still wondering why the option for **"enable annotation processing"** is non-existent in _netbeans 10.0_ – steven7mwesigwa Jun 28 '19 at 07:01
  • @steven7mwesigwa , I have never enabled "enable annotation processing" in netbeans. Make sure you [use Maven 3.5+][https://stackoverflow.com/a/14045358/338249] , with older versions the compiler plugin gives issues. Bundled in Netbeans 10 is 3.3.9 – rjdkolb Jun 28 '19 at 07:29
  • @rjdkolb This is my [`pom.xml` file](https://gist.github.com/steven7mwesigwa/f80356b8d375847a9acd5dcd7a81ae1c). May be am missing something. And am using maven 3.5.4. It throws errors [here](https://gist.github.com/steven7mwesigwa/b05c05a41a7ac65ee43829eb8a74acd5) – steven7mwesigwa Jun 28 '19 at 07:58
  • @steven7mwesigwa Ah, there is your issue. Remove the Lombok plugin, it's not needed. updating my answer – rjdkolb Jun 28 '19 at 08:52
  • 1
    @rjdkolb. I see. Interestingly, that fixed the problem. It now even works with the latest versions i.e lombok(v1.18.8), maven-compiler-plugin(v3.8.1), Apache maven (v3.6.1), Netbeans(v10). Thanks man. – steven7mwesigwa Jun 28 '19 at 09:02
8

I found a solution on https://groups.google.com/forum/#!topic/project-lombok/xbgzA86pvJs

=> update version of maven-compiler-plugin was the only way to make it work

Rolintocour
  • 2,934
  • 4
  • 32
  • 63
6

This worked with us:

  • remove <scope>provided</scope> from the Lombok dependency
  • clean and build the project
  • change the Lombok version (we changed from 1.16.20 to 1.16.16)
  • clean and build the project
  • restore the Lombok version and put back <scope>provided</scope>
  • clean and build the project
Paul Rambags
  • 639
  • 7
  • 5
1

configure the pom

<properties>
    <src.dir>src/main/java</src.dir>
</properties>

<profiles>
    <profile>
        <id>lombok-build</id>
        <properties>
            <src.dir>${project.build.directory}/generated-sources/delombok</src.dir>
        </properties>
    </profile>
</profiles>

<dependencies>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.8</version>
    <scope>provided</scope>
</dependency>
</dependencies>
    <build>
        <sourceDirectory>${src.dir}</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.16.16.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>delombok</goal>
                    </goals>
                    <configuration>
                        <sourceDirectory>src/main/java</sourceDirectory>
                        <addOutputDirectory>false</addOutputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Then, specify lombok-build as the active profile for various actions (build, debug etc) under Project Properties->Actions->Activate Profiles.

At this blog there is a github sample project and the configuration with pictures to use lastest version of maven+netbeans+lombok, that works for me.

Bruno Lee
  • 1,867
  • 16
  • 17