web-dev-qa-db-fra.com

Lombok ne compile pas en maven

J'essaie de compiler mon projet qui utilise Lombok via maven et j'obtiens le problème suivant:

[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] ------------------------------------------------------------------------

Où le premier type d'erreur concerne les champs de cette classe:

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;
}

et la deuxième erreur est quand une classe tente d'accéder aux accesseurs des classes de lombok

Mon maven pom.xml contient les éléments suivants:

<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>
10
mangusbrother

Je ne sais pas pourquoi mais vous avez une erreur de compilation à cause de maven-compiler-plugin. Si vous pouvez changer la version du plugin en version 3.5 et vérifier si cela fonctionnera.

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>

16
Renato Garcia

J'ai eu de la difficulté avec cela et j'ai conclu que Lombok 1.16+ et Java 8 constituaient un problème avec les versions précédentes du plugin de compilation de Maven. IDEA 2017.1 construisait le code sans erreurs, mais Maven lançait des erreurs de type "symbole non trouvé" sur des méthodes publiques qui étaient définitivement présentes dans un fichier jar décompilé. 

En effectuant la mise à niveau vers maven-compiler-plugin 3.6.1 dans l'ensemble de mon projet et de ses bibliothèques, j'ai pu le résoudre sans avoir à suivre le chemin de Delombok, ce que je voulais vraiment éviter.

3
Daniel Seltzer

Vous devrez également vérifier quelle version de Java est présente dans le chemin. Mon problème était avec Java 1.8 & 3.5 version. Pour que cela fonctionne, je devais passer à 1.7 & 3.5. S'il vous plaît noter que nous sommes toujours sur 1.7

0
user666

Vous devez d’abord localiser votre source lombok (annoté en Java avec lombok) dans src/main/lombok et ajouter le lombok-maven-plugin à votre projet comme suit:

<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>

Si vous n'aimez pas utiliser le lombok-maven-plugin, vous devez ajouter les éléments suivants:

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

Si vous voulez vraiment mettre votre source lomboked dans src/main/Java au lieu du /src/main/lombok par défaut vous devez utiliser cette méthode , ce qui n'est pas recommandé:

<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