web-dev-qa-db-ja.com

LombokはMavenでコンパイルしていません

Lavenkを使用するプロジェクトをmavenでコンパイルしようとしていますが、次の問題が発生しています。

[INFO] ------------------------------------------------------------------------
[INFO] Building akka-calculator-lib 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ akka-calculator-lib ---
[INFO] Deleting C:\dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ akka-calculator-lib ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ akka-calculator-lib ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 11 source files to C:\dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\operation\multiply\MultiplyResult.Java:[13,22] error: variable firstNumber not initialized in the default constructor
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\operation\multiply\MultiplyResult.Java:[14,22] error: variable secondNumber not initialized in the default constructor
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\operation\multiply\MultiplyResult.Java:[15,22] error: variable result not initialized in the default constructor
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[35,52] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[35,87] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[36,54] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[37,74] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[38,74] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[38,101] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[43,50] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[43,85] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[44,64] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[45,84] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[46,84] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[46,111] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[51,50] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[51,85] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[52,64] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[53,84] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[54,84] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[54,111] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[59,50] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[59,85] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[60,60] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[61,80] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[62,89] error: cannot find symbol
[ERROR] \dev\projects\Akka\akka-testing\akka-calculator\akka-calculator-lib\src\main\Java\com\mangusbrother\akka\calculator\lib\CalculatorActor.Java:[62,127] error: cannot find symbol
[INFO] 27 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] akka-parent ........................................ SUCCESS [  0.164 s]
[INFO] akka-testing ....................................... SUCCESS [  0.011 s]
[INFO] akka-calculator .................................... SUCCESS [  0.010 s]
[INFO] akka-calculator-lib ................................ FAILURE [  2.758 s]
[INFO] akka-calculator-creation ........................... SKIPPED
[INFO] akka-calculator-lookup ............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.120 s
[INFO] Finished at: 2016-02-14T19:01:21+01:00
[INFO] Final Memory: 14M/169M
[INFO] ------------------------------------------------------------------------

最初のエラータイプは、このクラスのフィールドです。

package com.mangusbrother.akka.calculator.lib.operation.multiply;


import com.mangusbrother.akka.calculator.lib.operation.MathematicalResult;
import lombok.Data;

/**
 * Created by Mangusbrother on 14/02/2016.
 */
@Data
public class MultiplyResult implements MathematicalResult {
    private static final long serialVersionUID = 738641818941986L;
    private final int firstNumber;
    private final int secondNumber;
    private final int result;
}

2番目のエラーは、クラスがロンボククラスからゲッターにアクセスしようとした場合です。

私のmaven pom.xmlには次のものが含まれています。

<properties>
    <lombok.version>1.16.6</lombok.version>
</properties>
<dependencies>
   <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.Apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
13
mangusbrother

理由はわかりませんが、maven-compiler-pluginが原因でコンパイラエラーが発生しました。プラグインのバージョンを3.5に変更して、機能するかどうかを確認してください。

9
grzesiekw
<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>
19
Renato Garcia

私はこれに非常に苦労し、Lombok 1.16 +およびJava 8はMavenのコンパイラプラグインの以前のバージョンの問題であると結論付けました。 IDEA 2017.1はエラーなしでコードをビルドしていましたが、Mavenは逆コンパイルされたjarファイルに確実に存在するパブリックメソッドで「シンボルが見つかりません」エラーをスローしていました。

プロジェクトとそのライブラリ全体でmaven-compiler-plugin 3.6.1にアップグレードすることで、デロンボクのパスをたどることなく解決できるようになりました。

4
Daniel Seltzer

また、Javaのバージョンがパスにあることを確認する必要があります。私の問題はJava 1.8&3.5 versionでした。 1.7と3.5に切り替えます。まだ1.7になっています。

0
user666

最初に、lombokソース(lombokで注釈されたJava)をsrc/main/lombokに配置し、プロジェクトに lombok-maven-plugin を次のように追加する必要があります。

<build>
  <plugins>
    <plugin>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok-maven-plugin</artifactId>
      <version>1.16.6.1</version>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>delombok</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Lombok-maven-pluginを使用したくない場合は、次を追加する必要があります。

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

デフォルトのsrc/main/Javaの代わりに/src/main/lombokにロンボクしたソースを配置することが本当に好きな場合 この方法で行かなければなりません これは推奨されません:

<build>
  <sourceDirectory>target/generated-sources/delombok</sourceDirectory>
  <testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory>
  <plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>1.16.6.1</version>
    <executions>
      <execution>
        <id>delombok</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>delombok</goal>
        </goals>
        <configuration>
          <addOutputDirectory>false</addOutputDirectory>
          <sourceDirectory>src/main/Java</sourceDirectory>
        </configuration>
      </execution>
      <execution>
        <id>test-delombok</id>
        <phase>generate-test-sources</phase>
        <goals>
          <goal>testDelombok</goal>
        </goals>
        <configuration>
          <addOutputDirectory>false</addOutputDirectory>
          <sourceDirectory>src/test/Java</sourceDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>
</build>
0
khmarbaise