我正在将现有的Java库转换为使用module-info.java。我广泛使用Lombok和泛型。当我运行"mvn package"时,会出现大量的错误,这些错误遵循以下模式:
[ERROR] /projects/app/src/main/java/com/whatever/app/server/handlers/HandlerCreateForumPost.java:[116,13] cannot find symbol
[ERROR] symbol: method <com.whatever.app.common.messages.CreateForumPostResults>builder()
[ERROR] location: class com.whatever.app.common.Response
导致错误的语句是:
return Response
.<CreateForumPostResults>builder()
.success(true)
.requestID(context.getRequestID())
.results(
CreateForumPostResults
.builder()
.id(forumPostID)
.build()
)
.build();
报告中错误的第116行是读取“.builder()”的那一行。
Response类位于com.whatever.app.common中,并定义为:
package com.whatever.app.common;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
@SuperBuilder
@Jacksonized
@Getter
@Setter
public class Response<T extends Response.Results> {
boolean success;
String message;
String requestID;
T results;
@SuperBuilder
@Jacksonized
@Getter
@Setter
public static class Results {
}
}
CreateForumPostResults类位于com.whatever.app.common.messages中,扩展了Response.Results:
package com.whatever.app.common.messages;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatever.app.common.AppResponse;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import java.util.UUID;
@SuperBuilder
@Getter
@Setter
@Jacksonized
public class AppCreateForumPostResults extends AppResponse.Results {
@JsonProperty("id")
UUID id;
}
我的 module-info.java 文件如下:
module com.whatever.app.common {
exports com.whatever.app.common;
exports com.whatever.app.common.messages;
requires com.fasterxml.jackson.annotation;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.datatype.jsr310;
requires com.google.common;
requires lombok;
}
我的POM如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>app</artifactId>
<groupId>com.whatever</groupId>
<version>0.9</version>
</parent>
<artifactId>app-common</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.jar.plugin.version>3.2.0</maven.jar.plugin.version>
<guava-version>23.0</guava-version>
<jackson-version>2.13.1</jackson-version>
<lombok-version>1.18.22</lombok-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava-version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok-version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
我怀疑在module-info.java中,使用Lombok的@Builder注解(以及可能其他注解)需要某些神奇的咒语或者与泛型相关的内容导致出现错误,但是我还没有找到具体原因。
我做错了什么?
非常感谢任何有见地的意见。
<annotationProcessorPaths>
所做的)。有关更多信息,请参见Project Lombok的maven页面。 - rzwitserloot