我在将我们的项目迁移到Java 9时遇到了问题。
在我更新为Java 9之后,尝试运行项目时,我遇到了编译器错误:-
Error:(6, 1) java: package javax.annotation is not visible
(package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph)
但我找到了解决方法。 我添加了lombok.config
文件。
然后,在向项目添加module-info.java
文件后,编译器再次显示错误。
Error:(10, 26) java: variable title not initialized in the default constructor
项目示例:
我们有一个名为 Store
的实体:
@AllArgsConstructor
@Getter
public class Story {
private final String title;
}
在根目录的包中,我有一个内容为module-info.java
的文件,其内容如下:
module javanine {
requires lombok;
}
在root的项目中,我有一个包含以下内容的 lombok.config 文件:
lombok.addJavaxGeneratedAnnotation = false
lombok.anyConstructor.suppressConstructorProperties = true
config.stopBubbling = true
在代码中的某个地方我调用它:
public static void main(String[] args) {
Story story = new Story("how as");
System.out.println(story.getTitle());
}