[英]Maven build failed because of Lambok annotated classes
我的項目是Spring-boot 2.1.1.RELEASE
應用程序。 這是一個多模塊的Maven項目。 這是父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>
example-common
對getter和setter使用lambok
批注。 這是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>
可以看到,我正在使用<annotationProcessorPaths>
。
@Data
public class CaptchaConfigs {
private String site;
private String secret;
}
@Data
注釋在maven build
生成過程中未生成getter / setter,因此出現錯誤
cannot find symbol [ERROR] symbol: method getSite()
cannot find symbol [ERROR] symbol: method getSecret()
該getter / setter存在於IDE中,我可以在大綱窗口中看到它們。
如果刪除@Data
並手動編寫getter / setter,則BUILD成功。
我已經為lambok
完成了每個配置( lambok-xxx.jar
),這就是為什么它在IDE中沒有給出編譯錯誤的原因,它僅在BUILD時失敗。
我在POM做錯了嗎?
PS:我正在使用Eclipse STS版本:3.9.6.RELEASE
請將maven-compiler-plugin
版本定義為3.5。 使用maven編譯器3.5.x annotationProcessorPaths
ProcessorPaths可以正常工作。
嘗試將以下內容添加到您的maven編譯器插件中。
<version>3.5.1</version>
我在同一Spring Boot 2.1.1.RELEASE
上使用Lombok
。 我認為問題出在您的Maven插件上。 下面是我的依賴項和插件,可以正常工作。
<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>
如我所料,這是我的配置。 從這里得到答案。
Maven編譯器未將getters / setters(使用Lombok生成)添加到生成jar文件
實際上,是導致該問題的原因是<compilerArgument>-proc:none</compilerArgument>
。 刪除它解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.