导入的 Maven 模块中的 Lombok
Lombok in imported Maven Module
我有以下 Maven 结构:
parent-module
|-model-module
|-model-contributor-module
在 model-module
中,我有用 @lombok.Data
注释的实体。当我在 model-module
上制作 mvn clean install
时,一切正常。第二个内部模块 model-contributor-module
在依赖项中包含 model-module
。当我尝试在 model-contributor-module
上执行相同的构建时,我收到错误消息 cannot find symbol
。
pom.xml
对于 model-module
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
和 pom.xml
对于 model-contributor-module
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
.....
<pluginManagement>
<plugins>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.8.0</version>
</plugin>
</plugins>
</pluginManagement>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.8.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>testDelombok</goal>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
如何修复这些编译错误?
[ERROR] /Users/superuser/Documents/workspace/project/test/src/main/java/com/company/services/impl/MyServiceImpl.java:[291,65] cannot find symbol
[ERROR] symbol: method getUserId()
将 lombok 依赖项移动到父 pom 的 dependencyManagement 元素中,以便它可以被子模块继承。您的插件在所有模块中都可用,但看起来 lombok 依赖项仅在模型模块中可用。
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
我有以下 Maven 结构:
parent-module
|-model-module
|-model-contributor-module
在 model-module
中,我有用 @lombok.Data
注释的实体。当我在 model-module
上制作 mvn clean install
时,一切正常。第二个内部模块 model-contributor-module
在依赖项中包含 model-module
。当我尝试在 model-contributor-module
上执行相同的构建时,我收到错误消息 cannot find symbol
。
pom.xml
对于 model-module
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
和 pom.xml
对于 model-contributor-module
:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
.....
<pluginManagement>
<plugins>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.8.0</version>
</plugin>
</plugins>
</pluginManagement>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.8.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>testDelombok</goal>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
如何修复这些编译错误?
[ERROR] /Users/superuser/Documents/workspace/project/test/src/main/java/com/company/services/impl/MyServiceImpl.java:[291,65] cannot find symbol
[ERROR] symbol: method getUserId()
将 lombok 依赖项移动到父 pom 的 dependencyManagement 元素中,以便它可以被子模块继承。您的插件在所有模块中都可用,但看起来 lombok 依赖项仅在模型模块中可用。
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>