Maven编译器插件看不到Lombok的注释
在我的应用程序中,我有3个这样的模块:
permissions (parent pom)
|---permission-api (just api, without main spring class)
|---permission-service (spring boot app)
在主模块的父pom中,我有pom,其中包含:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>permissions-api</module>
<module>permissions-service</module>
</modules>
和一些依赖项。现在我想用 Maven clean install 构建我的整个项目。 Permission-api模块已构建(lombok注释没有问题)。在pom中,对lombok的唯一引用是:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
无论如何,当我尝试仅构建权限服务或整个项目时,我遇到了这样的编译错误:
cannot find symbol
[ERROR] symbol: method getPermissionsList()
[ERROR] location: variable employee of type permissions.model.entity.Employee
我知道我应该将maven-compiler-plugin添加到pom.xml(我尝试也将其添加到父 pom 中),我这样做了,但没有帮助:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
你能告诉我我做错了什么吗?
in my application I have 3 modules like this:
permissions (parent pom)
|---permission-api (just api, without main spring class)
|---permission-service (spring boot app)
In parent pom in main module I have pom which contains:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>permissions-api</module>
<module>permissions-service</module>
</modules>
and some dependencies. Now I want to build my whole project with maven clean install. Permission-api module is build (there is no problem with lombok annotations). In pom only reference to lombok is:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
Anyway when I try to build only permission-serivce or entire project, I've got compilation errors like this:
cannot find symbol
[ERROR] symbol: method getPermissionsList()
[ERROR] location: variable employee of type permissions.model.entity.Employee
I know that I should add maven-compiler-plugin to pom.xml (I tried to add this to parent pom too) and I did but it does not help:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Can you tell me what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
同时我找到了解决办法。当我添加时,一切都开始工作:
可能缺少的依赖项导致了第一个编译错误,并且 Maven 编译器也错误地将下一个 lombok“缺少注释”显示为编译错误。
Meanwhile I found a solution. Everything started to works when I add:
Probably that missing dependency was causing first compilation error and maven compiler incorectly showed next lombok "missing annotations" as compilation errors too.
依赖关系,如 projectlombok.org 中所示,应该在“provided”范围内,这意味着仅需要它编译,但在运行时不需要:
这应该足够了。
Dependency, as in projectlombok.org, should be in scope 'provided', meaning that it's required only for compilation, but not needed in runtime:
This should be enough.
当您使用可选 true 时,您可以防止依赖关系传递给其子级。删除可选的,你应该没问题。
When you use optional true, you are preventing dependency being transferred to its children transitively. Remove optional and you should be fine.