简体   繁体   English

由于使用Lambok注释的类,Maven构建失败

[英]Maven build failed because of Lambok annotated classes

My project is a Spring-boot 2.1.1.RELEASE application. 我的项目是Spring-boot 2.1.1.RELEASE应用程序。 It's a multi-module maven project. 这是一个多模块的Maven项目。 This is the Parent POM file 这是父POM文件

<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. example-common对getter和setter使用lambok批注。 Here is the POM file of example-common 这是example-common的POM文件

<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> . 可以看到,我正在使用<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 @Data注释在maven build生成过程中未生成getter / setter,因此出现错误

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. 该getter / setter存在于IDE中,我可以在大纲窗口中看到它们。 显示生成方法的轮廓窗口

If I remove the @Data and write the getters/setters manually, the BUILD succeed. 如果删除@Data并手动编写getter / setter,则BUILD成功。

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. 我已经为lambok完成了每个配置( lambok-xxx.jar ),这就是为什么它在IDE中没有给出编译错误的原因,它仅在BUILD时失败。

Am I doing something wrong at POM? 我在POM做错了吗?

PS: I am using eclipse STS version: 3.9.6.RELEASE PS:我正在使用Eclipse STS版本: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. 请将maven-compiler-plugin版本定义为3.5。 With maven compiler 3.5.x annotationProcessorPaths , works fine. 使用maven编译器3.5.x annotationProcessorPaths ProcessorPaths可以正常工作。

Try adding below to your maven compiler plugin. 尝试将以下内容添加到您的maven编译器插件中。

<version>3.5.1</version>

I am using Lombok on same Spring Boot 2.1.1.RELEASE . 我在同一Spring Boot 2.1.1.RELEASE上使用Lombok I think the problem is with your maven plugin. 我认为问题出在您的Maven插件上。 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 Maven编译器未将getters / setters(使用Lombok生成)添加到生成jar文件

Actually it was the <compilerArgument>-proc:none</compilerArgument> which caused the issue. 实际上,是导致该问题的原因是<compilerArgument>-proc:none</compilerArgument> Removing it solved the issue. 删除它解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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