简体   繁体   中英

Maven build failed because of Lambok annotated classes

My project is a Spring-boot 2.1.1.RELEASE application. It's a multi-module maven project. This is the Parent POM file

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

    <name>example-parent</name>
    <description>example.com parent module</description>

    <groupId>com.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>example-common</module>
        <module>example-persistence</module>
        <module>example-rest</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

        </plugins>

        <pluginManagement>
            <plugins>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>${java-version}</source>
                        <target>${java-version}</target>
                        <compilerArgument>-proc:none</compilerArgument>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>

    </build>

    <properties>
        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
        <java-version>1.8</java-version>
    </properties>

</project>

The example-common uses lambok annotation for getters and setters. Here is the POM file of example-common

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

    <parent>
        <groupId>com.example</groupId>
        <artifactId>example-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>example-common</artifactId>
    <name>example-common</name>
    <description>module contains commons utils for all other modules</description>

    <dependencies>

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

        <!-- other dependencies -->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <compilerArgument>-proc:none</compilerArgument>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

As one can see, I am using <annotationProcessorPaths> .

@Data
public class CaptchaConfigs {

    private String site;
    private String secret;

}

@Data annotation is not generating getters/setters during the maven build process and hence giving the error

cannot find symbol [ERROR] symbol:   method getSite()
cannot find symbol [ERROR] symbol:   method getSecret()

The getters/setters are present in the IDE, I can see them in outline window. 显示生成方法的轮廓窗口

If I remove the @Data and write the getters/setters manually, the BUILD succeed.

I have done every configuration( lambok-xxx.jar ) for lambok and that's why it's not giving the compilation error in the IDE, it fails only at BUILD.

Am I doing something wrong at POM?

PS: I am using eclipse STS version: 3.9.6.RELEASE

在此处输入图片说明 select Third option and try if not work you follow the below link might help

answer somehow related to your issue click on the link

Please define maven-compiler-plugin version to 3.5. With maven compiler 3.5.x annotationProcessorPaths , works fine.

Try adding below to your maven compiler plugin.

<version>3.5.1</version>

I am using Lombok on same Spring Boot 2.1.1.RELEASE . I think the problem is with your maven plugin. Below is my dependency and plugin which works fine.

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

It was my configuration, as I expected. Got the answer from here.

Maven compiler not adding getters/setters(generated using Lombok) to the build jar file

Actually it was the <compilerArgument>-proc:none</compilerArgument> which caused the issue. Removing it solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM