Lombok not working in a Netbeans project

后端 未结 4 1486
遥遥无期
遥遥无期 2021-02-08 04:36

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

I included using Maven:

    
        org.projectlombok<         


        
相关标签:
4条回答
  • 2021-02-08 04:48

    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
    0 讨论(0)
  • 2021-02-08 05:03

    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

    0 讨论(0)
  • 2021-02-08 05:04

    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.

    0 讨论(0)
  • 2021-02-08 05:11

    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

    <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.

    0 讨论(0)
提交回复
热议问题