How to configure Lombok with maven-compiler-plugin?

前端 未结 7 1978
长情又很酷
长情又很酷 2020-12-15 07:12

I have a root module and submodule in maven in the project. I am trying to use Lombok. I have added


    org.projectlombok&         


        
相关标签:
7条回答
  • 2020-12-15 07:16

    I had this same issue and nothing worked, i.e. maven plugin version, annotationProcessorPaths, provided scope, etc.

    In the end I narrowed it down to having a static import on an @UtilityClass method from a class within the same project, i.e. not brought in from a dependency. This caused annotation processing to fail, even for unrelated classes, and made it look like lombok code was just not being compiled properly. Getting rid of the static import made it all work.

    There's an open issue on Github for this, though apparently it's too hard to fix.

    0 讨论(0)
  • 2020-12-15 07:27

    I'm not sure what the difference is between lombok and lombok-maven-plugin, but my projects are configured with this dependency:

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.16.12.0</version>
        </dependency>
    

    I haven't experimented with root and submodule poms yet, as my projects all tend to be rather isolated from each other. Not sure if that could be causing an issue for you.

    If you are using Eclipse, have you run the lombok.jar file and pointed it to your eclipse.exe file? it needs to modify the .exe in order for Eclipse to know that those getters and setters are coming, so that Eclipse doesn't complain during development.

    Edit: I'm using maven-compiler-plugin:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
    
    0 讨论(0)
  • 2020-12-15 07:28

    Maven Groovy and Java + Lombok

    The solution on this stack overflow answer worked for me. I missed adding the javaAgentClass earlier

    0 讨论(0)
  • 2020-12-15 07:30

    In case of anyone using JDK 11

        <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <arg>-sourcepath</arg>
                        <arg>${project.basedir}/src/main/java${path.separator}${project.basedir}/target/generated-sources/annotations${path.separator}/</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
  • 2020-12-15 07:30

    I was using Java 8 and @Getter(onMethod = @__({@NoSerialization})) and @Getter(onMethod = @__({@Translation(messageKey = "translation.key")})) onX annotations. And I get duplicate element '<any?>' in annotation @<any?>. in error output. Looks like guys from Lombok have such issue with Java 8 for a long time link to issue on github. Lombok does not handle annotations with parameters like messageKey in annotation above. it works only with annotations without parameters and annotations with only value parameter (when you don't write the name of parameter).

    0 讨论(0)
  • 2020-12-15 07:37

    use:

    <scope>provided</scope>
    

    in pom.xml like that:

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
    0 讨论(0)
提交回复
热议问题