Lombok 1.18.2 不适用于 Maven 和 jdk 10
Lombok 1.18.2 does not work with maven and jdk 10
当我尝试在 JDK 10 下编译我的 Java Projekt 时,Lombok 没有创建 getters/setters。
使用Lombok注解的class
package com.testcompany.data;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class DataInfo {
private Map<String,String> metadata = new HashMap<>();
private String extractedString;
}
Lombok 的用法注释class
String test = dataInfo.getExtractedString();
我正在使用以下版本将我的源编译为 java10:
- maven (3.5.4)
- maven-compiler-plugin 3.8.0
- Java10(颠覆2)
- 龙目岛 1.18.2
pom.xml
在依赖部分
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
并且在 maven-compiler-plugin 部分
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
当我通过 mvn install 编译时,出现以下错误:
MemberRegistration.java:[50,36] cannot find symbol
symbol: method getExtractedString()
location: variable dataInfo of type com.testcompany.data.DataInfo
使用 jdk 10 时,我需要做哪些不同的事情吗?
感谢大家!
主要问题是,我使用了编译器参数“-proc:none”,这意味着 "compilation takes place without annotation processing..."。所以我删除了这个参数。除此之外,还建议使用以下编译器参数(参见 compilerArgs 部分):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
<release>10</release>
<executable>javac10</executable>
<fork>false</fork>
<encoding>UTF-8</encoding>
<!-- see https://github.com/rzwitserloot/lombok/issues/985#issuecomment-356135454 -->
<compilerArgs>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
当我尝试在 JDK 10 下编译我的 Java Projekt 时,Lombok 没有创建 getters/setters。
使用Lombok注解的class
package com.testcompany.data;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class DataInfo {
private Map<String,String> metadata = new HashMap<>();
private String extractedString;
}
Lombok 的用法注释class
String test = dataInfo.getExtractedString();
我正在使用以下版本将我的源编译为 java10:
- maven (3.5.4)
- maven-compiler-plugin 3.8.0
- Java10(颠覆2)
- 龙目岛 1.18.2
pom.xml 在依赖部分
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
并且在 maven-compiler-plugin 部分
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
当我通过 mvn install 编译时,出现以下错误:
MemberRegistration.java:[50,36] cannot find symbol
symbol: method getExtractedString()
location: variable dataInfo of type com.testcompany.data.DataInfo
使用 jdk 10 时,我需要做哪些不同的事情吗?
感谢大家! 主要问题是,我使用了编译器参数“-proc:none”,这意味着 "compilation takes place without annotation processing..."。所以我删除了这个参数。除此之外,还建议使用以下编译器参数(参见 compilerArgs 部分):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
<release>10</release>
<executable>javac10</executable>
<fork>false</fork>
<encoding>UTF-8</encoding>
<!-- see https://github.com/rzwitserloot/lombok/issues/985#issuecomment-356135454 -->
<compilerArgs>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>