Плагин Maven Lombok на Java 10: аннотации не найдены в Maven
Я знаю проблему IDE не понимая ломбок. Но сейчас, в новом проекте, у меня есть противоположная проблема: идея понимает это, а maven - нет.
Когда я добавляю плагин lombok в maven и запускаю чистую установку, плагин lombok не может преобразовать классы, потому что утверждает, что пакет lombok не существует.
Это мой 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>
(примечания от pom: уровень языка - java 10, исходная кодировка utf-8, я использую мозаичные модули в многокомпонентной сборке)
ошибки, которые я получаю, примерно такие. Я попытался установить область действия org.projectlombok:lombik для компиляции или предоставления, без каких-либо различий в результате.
Я был бы очень благодарен, если бы у кого-нибудь была идея, как это исправить?
[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]
1 ответ
Обновление конфигурации до следующего может помочь решить проблему:
<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>
Я дал этому попытку и целевые файлы, созданные с помощью команды mvn clean install
имеет код деломбокса следующим образом:
Хотя после генерации я вижу в IDE сообщение "module-info.java уже существует в модуле".