我有以下 Maven 结构:
parent-module
|-model-module
|-model-contributor-module
Run Code Online (Sandbox Code Playgroud)
在model-module我有用 注释的实体@lombok.Data。当我穿上mvn clean install一切都好model-module。第二个内部模块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>
Run Code Online (Sandbox Code Playgroud)
对于:pom.xmlmodel-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>
Run Code Online (Sandbox Code Playgroud)
如何修复这些编译错误?
[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()
Run Code Online (Sandbox Code Playgroud)
将该 lombok 依赖项移至父 pom 的 dependencyManagement 元素中,以便子模块可以继承它。您在所有模块中都可以使用该插件,但看起来 lombok 依赖项仅在模型模块中可用。
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3213 次 |
| 最近记录: |