Maven编译器插件看不到Lombok的注释

发布于 2025-01-11 11:00:11 字数 2593 浏览 0 评论 0原文

在我的应用程序中,我有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如若梦似彩虹 2025-01-18 11:00:11

同时我找到了解决办法。当我添加时,一切都开始工作:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-envers</artifactId>
    <version>${hibernate.version}</version>
</dependency>

可能缺少的依赖项导致了第一个编译错误,并且 Maven 编译器也错误地将下一个 lombok“缺少注释”显示为编译错误。

Meanwhile I found a solution. Everything started to works when I add:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-envers</artifactId>
    <version>${hibernate.version}</version>
</dependency>

Probably that missing dependency was causing first compilation error and maven compiler incorectly showed next lombok "missing annotations" as compilation errors too.

栩栩如生 2025-01-18 11:00:11

依赖关系,如 projectlombok.org 中所示,应该在“provided”范围内,这意味着仅需要它编译,但在运行时不需要:

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

这应该足够了。

Dependency, as in projectlombok.org, should be in scope 'provided', meaning that it's required only for compilation, but not needed in runtime:

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

This should be enough.

追我者格杀勿论 2025-01-18 11:00:11

当您使用可选 true 时,您可以防止依赖关系传递给其子级。删除可选的,你应该没问题。

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

When you use optional true, you are preventing dependency being transferred to its children transitively. Remove optional and you should be fine.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文