【发布时间】:2019-03-19 10:04:35
【问题描述】:
我的项目是一个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
【问题讨论】: