在将我们的项目迁移到 时遇到问题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;
}
在 root 的包中我有
module-info.java
内容:module javanine {
requires lombok;
}
在根的项目中,我有 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());
}
最佳答案
只需将您的模块配置如下:
module moduleName {
requires static lombok;
}
关于java-9 - module-info.java 不适用于 Java 9 中的 lombok,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47460373/