简体   繁体   English

Java 10 上的 maven lombok 插件:在 maven 中找不到注释

[英]maven lombok plugin on Java 10: annotations not found in maven

I know the problem of IDEs not understanding lombok.我知道 IDE 不理解 lombok 的问题。 But right now, on a new project, I have the opposite problem: Idea does understand it, but maven does not.但是现在,在一个新项目中,我遇到了相反的问题:Idea 确实理解它,但 maven 不理解。

When I add the lombok plugin to maven, and run a clean install, the lombok plugin fails to transform the classes becuase it claims that the package lombok does not exist.当我将 lombok 插件添加到 maven 并运行全新安装时,lombok 插件无法转换类,因为它声称包 lombok 不存在。

This is my pom.xml:这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>henkk</artifactId>
        <groupId>de.newcron</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>henkk-chat-api</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.18.0.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                        <configuration>
                            <addOutputDirectory>false</addOutputDirectory>
                            <sourceDirectory>src/main/java</sourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>


</project>

(notes from parent pom: language level is java 10, source encoding utf-8, I am using jigsaw modules in a multi module build) (来自父 pom 的注释:语言级别为 java 10,源编码为 utf-8,我在多模块构建中使用拼图模块)

the errors i am getting are something like this.我得到的错误是这样的。 I tried to set the scope of org.projectlombok:lombik to either compile or provided, without any difference in the result我试图将 org.projectlombok:lombik 的范围设置为编译或提供,结果没有任何区别

I would be very thankful if anyone had an idea on how to fix that?如果有人知道如何解决这个问题,我将不胜感激?

[INFO] ---------------------< de.newcron:henkk-chat-api >----------------------
[INFO] Building henkk-chat-api 1.0.0-SNAPSHOT                             [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ henkk-chat-api ---
[INFO] 
[INFO] --- lombok-maven-plugin:1.18.0.0:delombok (default) @ henkk-chat-api ---
[WARNING] Unable to detect tools.jar; java.home is /usr/lib/jvm/java-11-openjdk-amd64
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/module-info.java:3: error: module not found: lombok
    requires lombok;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:4: error: package lombok does not exist
import lombok.AllArgsConstructor;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:5: error: package lombok does not exist
import lombok.ToString;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:7: error: cannot find symbol
@AllArgsConstructor
 ^
  symbol: class AllArgsConstructor
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:8: error: cannot find symbol
@ToString
 ^
  symbol: class ToString
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatIdentity.java:6: error: cannot find symbol
@AllArgsConstructor
 ^
  symbol: class AllArgsConstructor
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatIdentity.java:7: error: cannot find symbol
@EqualsAndHashCode
 ^
  symbol: class EqualsAndHashCode
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatIdentity.java:8: error: cannot find symbol
@ToString
 ^
  symbol: class ToString
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatIdentity.java:4: error: package lombok does not exist
import lombok.*;
^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:5: error: package lombok does not exist
import lombok.AllArgsConstructor;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:6: error: package lombok does not exist
import lombok.EqualsAndHashCode;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:7: error: package lombok does not exist
import lombok.NonNull;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:8: error: package lombok does not exist
import lombok.ToString;
             ^
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:10: error: cannot find symbol
@AllArgsConstructor
 ^
  symbol: class AllArgsConstructor
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:11: error: cannot find symbol
@EqualsAndHashCode
 ^
  symbol: class EqualsAndHashCode
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:12: error: cannot find symbol
@ToString
 ^
  symbol: class ToString
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatIdentity.java:10: error: cannot find symbol
    @NonNull
     ^
  symbol:   class NonNull
  location: class SimpleChatIdentity
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:14: error: cannot find symbol
    @NonNull
     ^
  symbol:   class NonNull
  location: class SimpleChatMessage
/home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/simple/SimpleChatMessage.java:16: error: cannot find symbol
    @NonNull
     ^
  symbol:   class NonNull
  location: class SimpleChatMessage
[INFO] Delombok complete.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ henkk-chat-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ henkk-chat-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/matthias/dev/henkk/henkk-chat-api/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:[10,32] variable sender not initialized in the default constructor
[ERROR] /home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:[11,31] variable message not initialized in the default constructor
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] henkk 1.0.0-SNAPSHOT ............................... SUCCESS [  0.991 s]
[INFO] henkk-chat-api ..................................... FAILURE [  1.135 s]
[INFO] henkk-application .................................. SKIPPED
[INFO] henkk-chat-stdin 1.0.0-SNAPSHOT .................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.277 s
[INFO] Finished at: 2018-08-29T18:12:12+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project henkk-chat-api: Compilation failure: Compilation failure: 
[ERROR] /home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:[10,32] variable sender not initialized in the default constructor
[ERROR] /home/matthias/dev/henkk/henkk-chat-api/src/main/java/de/newcron/henkk/chat/api/MessageReceivedEvent.java:[11,31] variable message not initialized in the default constructor
[ERROR] -> [Help 1]

Updating the configuration to the following could help fix the issue:-将配置更新为以下内容可能有助于解决问题:-

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.2</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.2</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.18.0.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>delombok</goal>
                    </goals>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <addOutputDirectory>false</addOutputDirectory>
                        <sourceDirectory>src/main/java</sourceDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I gave this a try and the target files generated with the command mvn clean install has the delomboked code as follows:-我试了一下,使用命令mvn clean install生成的目标文件具有如下的 delomboked 代码:-

在此处输入图片说明

Though after the generation, I get to see in the IDE a message reading "module-info.java already exists in the module".虽然在生成之后,我在 IDE 中看到一条消息,上面写着“module-info.java 已经存在于模块中”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM