我有下面的 Pojo 类,我添加了@Datafrom Lombok。
该项目在 Eclipse IDE 中运行良好,我什至可以在 IDE 的大纲窗口中看到 getter/setter。但是,当我运行mvn clean install或Run As Maven Install从IDE,得到没有任何错误产生的jar文件,但目前还没有(方法getters,setters,equals,hashcode),这是由产生Lombok。

由于 IDE 正在显示方法,因此 POM 文件中的 maven 编译器插件肯定存在一些问题。我尝试了所有可能的解决方案,但没有任何效果。
这是POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test-boot</name>
<description>Demo project</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.3.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我已将测试项目推送到Github。可以从这里克隆:https : //github.com/Puspendert/test-lambok.git
更新:为了验证 getter/setter 的生成是否会影响任何事情,我更改了 main 方法:
@SpringBootApplication
public class TestBootApplication {
public static void main(String[] args) {
User user = new User();
user.setName("hero");
System.out.println(user.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
和繁荣,正如预期的那样,该项目在mvn clean install以下方面给出了编译错误:
[INFO] Building test-boot 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/puspender/git/test-lambok/test-boot/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[11,21] cannot find symbol
symbol: method setName(java.lang.String)
location: variable user of type com.example.User
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[12,40] cannot find symbol
symbol: method getName()
location: variable user of type com.example.User
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
Run Code Online (Sandbox Code Playgroud)
请提出建议,这里可能有什么问题?
您正在明确禁用注释处理!
<compilerArgument>-proc:none</compilerArgument>
删除这一行 - lombok 毕竟是一个注释处理库 - 一切(应该)工作文件
编辑:为了公平起见,还有另一个已删除的答案(出于某种原因)也表明
| 归档时间: |
|
| 查看次数: |
3286 次 |
| 最近记录: |