gpt4 book ai didi

java - 导入 Maven 模块中的 Lombok

转载 作者:行者123 更新时间:2023-12-01 20:12:41 34 4
gpt4 key购买 nike

我有以下 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 上执行相同的构建时,我收到错误无法找到符号

pom.xml 用于模型模块:

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

以及 model-contributor-modulepom.xml:

<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>

关于java - 导入 Maven 模块中的 Lombok,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46429703/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com