32

I am trying to compile my project that uses lombok through maven and i am getting the following issue:

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

Where the first error type is for the fields in this class:

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

and the second error is when a class tries to access getters from lombok classes

My maven pom.xml has the following in it:

<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>
15
  • Where are the souces located? src/main/java, src/main/lombok?
    – Tunaki
    Commented Feb 14, 2016 at 17:44
  • java. Do they have to be under lombok? Commented Feb 14, 2016 at 17:49
  • Yes. Try to move them.
    – Tunaki
    Commented Feb 14, 2016 at 17:52
  • It doesn't compile them under src/main/lombok so it's not working Commented Feb 14, 2016 at 17:55
  • 2
    How did you ran Maven? And what's the error? You should run mvn clean package.
    – Tunaki
    Commented Feb 14, 2016 at 17:57

9 Answers 9

71

Add annotationProcessorPaths to your maven-compiler-plugins configurations:

<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>
6
  • 7
    please put helpful comments about your answer
    – EyuelDK
    Commented May 22, 2017 at 16:00
  • 3
    With maven compiler 3.6.x use "annotationProcessorPaths", works fine. Commented Aug 25, 2017 at 12:38
  • 1
    Thanks @RenatoGarcia, this was the right answer to me using Java 8 and maven compiler 3.6.2!
    – jfneis
    Commented May 17, 2018 at 19:23
  • 1
    Adding lombok path to annotationProcessorPaths worked for me as well
    – petre
    Commented May 19, 2018 at 13:16
  • 2
    This one does the trick. I've tried over many answers about enable Annotation processor but they are not enough to make it work. This should be the answer!
    – Andiana
    Commented Oct 9, 2019 at 16:59
19

I don't know why but you got compiler error because of maven-compiler-plugin. If you can please change plugin version to 3.5 and check if it will work.

2
  • 1
    This was the issue. The above given configuration with the compiler plugin upgraded to 3.5.1 will let you use lombok without having to move anything from src/main/java or add extra plugins or inherit external parents Commented Feb 14, 2016 at 18:58
  • 3
    my maven-compiler-plugin is 3.8.1 and i'm still getting this error. Commented Jul 13, 2022 at 8:17
10

My working configuration is as below.

In the pom file:

     <properties>
        <java.version>14</java.version>
        <lombok-version>1.18.12</lombok-version>
    </properties>

     <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok-version}</version>            
            <optional>true</optional>
        </dependency>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>14</source>
                    <target>14</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok-version}</version>
                        </path>
                    </annotationProcessorPaths>                 
                </configuration>
            </plugin>
        </plugins>
    </build>

Maven compiler plugin version 3.8.1 is significant here as the older version didn't work for me.

In the module-info.java

 requires static lombok;
1
  • This one worked for me. Before this when inspecting the generated class files the lombok methods were missing Commented Oct 15, 2020 at 19:32
7

I struggled mightily with this and concluded that Lombok 1.16+ and Java 8 are a problem with earlier versions of Maven's compiler plugin. IDEA 2017.1 was building the code without errors, but Maven was throwing 'symbol not found' errors on public methods that were definitely there in a decompiled jar file.

By upgrading to maven-compiler-plugin 3.6.1 across my project and its libraries I was able to get it resolved without having to go down the Delombok path, which I really wanted to avoid.

1

First you should locate your lombok source (java annotated with lombok) into src/main/lombok and add the lombok-maven-plugin to your project like this:

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

If you don't like to use the lombok-maven-plugin you need to add the following:

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

If you really like to put your lomboked source into src/main/java instead of the default /src/main/lombok you have to go this way which is not recommended:

<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>
3
  • You use the delombok plugin if you want to generate de-lombok'ed sources though no? I don't need expanded sources. I have the dependency already and the files are still not compiling Commented Feb 14, 2016 at 18:40
  • there is no "delombok plugin".
    – specializt
    Commented Jan 26, 2017 at 16:56
  • I don't use a delombok plugin only the goal of it See here: awhitford.github.io/lombok.maven/lombok-maven-plugin/usage.html
    – khmarbaise
    Commented Jan 27, 2017 at 9:53
1

Although the OP's problem appears to have been solved these symptoms can also be caused by this:

If Lombok is working in your IDE but behaving like its not generating any methods etc in the Maven build a cause of this can be that Maven has been set to use a different compiler to the javac compiler, which may have different instructions.

For example if your POM (or parent POM) contains something like this:

    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerId>eclipse</compilerId>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

In that case the eclipse compiler is being used, this compiler is much less lombok friendly and has special instructions.

[For my case that was bending the build process too out of shape and we decided not to use lombok as a result, sadly]

1

I am using macos with arm64, i also get these errors, but it was due to my JDK version being much higher than my java version in the pom. when installing similar version (via sdkman) to that what is in my pom, the build was successful. hope that helps someone.

0

You will also need to check what version of java is there in path . My issue was with Java 1.8 & 3.5 version . To get it working I had to switch to 1.7 & 3.5 . Please note we are still on 1.7

-2

Increase the stack size of the JVM using this argument: -Xss10240m

MAVEN_OPTS

set MAVEN_OPTS=-Xss10240m" or export MAVEN_OPTS="-Xss10240m".

_JAVA_OPTIONS

_JAVA_OPTIONS="-Xss10240m".

maven-compiler-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <compilerArgs>
            <arg>-Xss10240m</arg>
        </compilerArgs>
    </configuration>
</plugin>

spring-boot-maven-plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <jvmArguments>
            -Xss10240m
        </jvmArguments>
    </configuration>
</plugin>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.