Reputation: 4327
I'm using project lombok for the first time and I have problems compiling the project via maven when I run the build I receive errors where methods annotated with project lombok annotations are called.
This is the annotated parameter:
private @Getter @Setter String paymentNonce = null;
and in this line for example the maven breaks the build:
if (!StringUtilities.isNullOrEmpty(getPaymentNonce())) {
this is my maven dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.4</version>
</dependency>
the maven error:
[INFO] Compiling 158 source files to C:\java\repos\luna\cloudflow\cloudflow-ejb\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[94,38] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[97,106] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[142,2] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\ShoppingCart.java:[27,6] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\ShoppingCart.java:[32,75] error: cannot find symbol
.....
I'm using java 8
Upvotes: 45
Views: 63312
Reputation: 123
In my case,I annotated @Nullable into Optional generic type.It seem not unsupported this "Target".
public record DTO(Optional<@Nullable Integer> userId){
}
Upvotes: 0
Reputation: 1349
If none of the other (common) answers worked for you::
(this is an Rare case thats Unlikely to fit yours)
Comment.java
, public class Comments
, no package declaration).mvn install
(using right click on the project in Eclipse)[ERROR] /G:/XXX/XXX/XXX/src/main/java/XXXX/SomeClassAA.java:[37,28] cannot find symbol
symbol: method add(SomeClassBB)
---
mvn install
twice, Upvotes: 0
Reputation: 1
I designed the <annotationProcessor>
in maven-compiler-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
Upvotes: 0
Reputation: 12695
In my case, I fixed two config and it works.
someone set compiler args to -proc:none
in compiler args:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven_compiler_version}</version>
<configuration>
<compilerArgs>
<!--remove below compiler arg fixed my problem-->
<compilerArg>-proc:none</compilerArg>
<compilerArg>-parameters</compilerArg>
</compilerArgs>
<fork>true</fork>
<source>${java_source_version}</source>
<target>${java_target_version}</target>
<encoding>${file_encoding}</encoding>
</configuration>
</plugin>
Build, Execution, Deployment
> Compiler
> Java Compiler
> Use compiler
is Ajc
.
I use lombok 1.18.24 and java 8.
After remove -proc:none
compiler argument and change compiler to javac
, the project could be compiled in IDEA maven or in standalone maven.
Upvotes: 0
Reputation: 31
In my case i have got this error because a compile error in other class but the lombok was suppressing the real problem. I recommend you to take a look in your classes to find some error. I hope it helps you
Upvotes: 3
Reputation: 7754
For me the solution was, to do not use import static
on lombok builder. Changing:
import static Foo.builder;
builder().id(1).build()
To:
Foo.builder().id(1).build()
Upvotes: 0
Reputation: 3440
I was actually able to solve this by following an answer posted here :
MapStruct and Lombok not working together
Basically I had to add lombok
to the maven-compiler-plugin
<annotationProcessorPaths>
Upvotes: 18
Reputation: 1634
For other users using JDK9 and above you should add annotationProcessorPaths to maven compiler plugin
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</path>
</annotationProcessorPaths>
Upvotes: 10
Reputation: 31
I don't know but for some reason it solves my problem.
I have two classes that use @Builder to generate a build method. But one is normal, the other one is abnormal. I have checked everything and it seems ok.
But when I run mvn
to compile my project, the error is as follows:
Can't not find the symbol method builder()
import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class A {
}
import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class B {
}
Class A compiles correctly, but Class B reports the problem above.
I tried to replace the version of the Lombok JAR, but even though I set the version to latest, it's not ok.
So, I tried to import Lombok per class that I reference.
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class B {
}
It works! It seems a bug.
Upvotes: 0
Reputation: 378
try to specify parameter for "lombok" module within dependencies.I faced the same issue and resolved this by this work around.
Upvotes: 0
Reputation: 577
My solution was to prefix the annotation with lombok package name.
@lombok.Builder
@lombok.experimental.Accessors(prefix = "m", chain = true)
rather than
@Builder
@Accessors(prefix = "m", chain = true)
Upvotes: 6
Reputation: 574
If you're using Lombok related static methods (mainly @Builder) with static imports, you might experience similar issues (even in other parts of your code!).
There is an open issue about it: https://github.com/rzwitserloot/lombok/issues/979
The current workaround is to simply not use static imports, e.g. change
import static my.org.Foo.FooBuilder
...
FooBuilder builder = Foo.builder();
to:
Foo.FooBuilder builder = Foo.builder(); // note >>Foo.<<FooBuilder; without static import
Upvotes: 8
Reputation: 29
If you are using lombok annotations in static classes in that case you will have to mention the full name of the class ie. instead of @Data
to @lombok.Data
. This has worked for me.
Upvotes: 2
Reputation: 454
In short, upgrade maven-compiler-plugin
to up 2.4
, or downgrade lombok
to below 1.14.*
.
It seems that maven-compiler-plugin
below 2.4
doesn't support javax.annotation.processing.Processor
with a name with $
.
Update: You can configuration maven-compiler-plugin
to fork
, or update plexus-compiler-javac
to 1.8.6
. (maven-compiler-plugin
2.3.2
requires 1.8.1
, and 2.4
requires 1.8.6
)
Since 1.16
, lombok uses ShadowClassLoader
, which prevents the IDE promotion for lombok's internal class. However, it doesn't use the ShadowClassLoader
if the classloader is org.codehaus.plexus.compiler.javac.IsolatedClassLoader
. (I don't known why lombok guys use hard code to solve other issue may related with plexus-compiler-javac
.)
maven-compiler-plugin
2.4
, or rather, plexus-compiler-javac
1.8.6
, doesn't use org.codehaus.plexus.compiler.javac.IsolatedClassLoader
, so it works again.
Upvotes: 3
Reputation: 5796
In my case it was solved by upgrading JDK (was 1.8.0_66, now 1.8.0_92)
Upvotes: 0
Reputation: 431
Had the same problem using maven-compiler-plugin v.2.3.2 After updating the version up to 3.5 problem disappeared
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
...
</configuration>
</plugin>
Hope this helps
Upvotes: 38
Reputation: 4327
I have downgraded the lombok to 1.14.8 this version works with maven build, I havent found why the 1.16 verson is not working :(
Upvotes: 12
Reputation: 34462
Could it be that you've specified -proc:none
or explicitly specified annotation processors using -processor <processorclass>
in your java compilation (javac)?
Upvotes: 1