This won’t have been OP’s problem, but for anyone else who tries everything with no success:
I had similar symptoms. Whenever I built after a mvn clean
, it wouldn’t find log
, or getXYZ()
, or builder()
, or anything.
[ERROR] symbol: variable log
[ERROR] location: class com.example.MyClass
[ERROR] /Path/To/Some/Java/src/main/com/example/MyClass.java:[30,38] cannot find symbol
[ERROR] symbol: method builder()
[ERROR] location: class com.example.MyClass
After reading every answer I could find about QueryDSL/JPA/Hibernate/Lombok/IntelliJ/Maven issues to no avail, I worked out that the culprit was a single static import of a @Getter
method that was annotated on a static field.
Spring 1.15.14.RELEASE, Intellij 2019.1.1
@SpringBootApplication
public class BarApplication implements ApplicationContextAware {
@Getter
private static ApplicationContext applicationContext;
// ... start Spring application, and grab hold of ApplicationContext as it comes past
}
import ...
import static BarApplication.getApplicationContext;
@Slf4j
public class IMakeItAllFail {
public IMakeItAllFail() {
log.info("{}", getApplicationContext());
}
}
@Slf4j
public class Foo {
Foo() {
log.info("I fail to compile but I have nothing to do with the other classes!");
}
}
I have the lombok plugin in Eclipse and enabled annotation processing in Eclipse under java compiler, but still it is unable to recognize the log statements when I use @Slf4j annotation.
Do we have to make any other settings?
Roel Spilker
30.7k9 gold badges66 silver badges56 bronze badges
asked May 18, 2013 at 18:46
5
You also have to install Lombok into Eclipse.
See also this answer on how to do that or check if Lombok is installed correctly.
Full Disclosure: I am one of the Project Lombok developers.
answered May 24, 2013 at 8:18
Roel SpilkerRoel Spilker
30.7k9 gold badges66 silver badges56 bronze badges
6
I also faced the similar issue on log and @Slf4j on my STS environment. To resolve this, here is what I did on spring tool suite (sts-4.4.0.RELEASE) and lombok-1.18.10.jar (current latest version available in mavenrepository).
-
If having maven project, ensure lombok dependency added to it. Else you need manually add the jar to your project classpath.
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency> -
Clean build the maven application. This will download lombok jar in your .m2 location by default from maven repository.
The path would beorgprojectlomboklombok1.18.10
-
Now open command prompt and navigate to the lombok path and execute command
java -jar lombok-1.18.10.jar
C:xxxxxxorgprojectlomboklombok1.18.10>java -jar lombok-1.18.10.jar
-
Opens up lombok dialog box. If see message
Can't find IDE
ClickSpecify location...
Provide the path to your STS root locationMy case it is
C:appssts-4.4.0.RELEASESpringToolSuite.exe
Install/Update
-
Install successful
Click Quit Installer -
Now in explorer navigate to your STS root path.
C:appssts-4.4.0.RELEASE
We seelombok.jar
placed in the sts root path
Now edit in notepadSpringToolSuite4.ini
file
We see following appended at the end-javaagent:C:appssts-4.4.0.RELEASElombok.jar
-
Start STS using
SpringToolSuite4.exe
Clean, rebuild your project.
answered Oct 17, 2019 at 9:12
vinsinrawvinsinraw
1,9571 gold badge15 silver badges17 bronze badges
3
So like others, i also faced this issue. Below is what I did.
- Installed lombok.jar like explained here.
- Tried restarting eclipse. (Did not work)
- Tried refreshing gradle project. (Did not work)
- tried what Hervian suggested in his answer here. (Did not work)
- Closed the projects, deleted from workspace and then re-imported. Bam!! Worked.
answered Aug 8, 2020 at 13:24
Manish BansalManish Bansal
2,2602 gold badges19 silver badges36 bronze badges
1
I got the same error even after Lombok was installed. For me the solution was to add another lombok annotation (i used @Data) to my class after which the eclipse errors went away. Perhaps this force refreshed some cache.
Of course, I simply deleted the @Data annotation afterwards.
answered Jun 27, 2018 at 11:18
HervianHervian
1,0901 gold badge12 silver badges19 bronze badges
2
this got the fix to me by adding the slf4j dependency, Lombok can identify the slf4j but does not get the download, this is true for java project if you are using spring boot then slf4j comes by default.
here are my dependencies
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
answered Nov 17, 2019 at 14:36
NaveenNaveen
4815 silver badges6 bronze badges
Содержание
- Doesn’t compile with Gradle 5 RC #1945
- Comments
- Short description
- Expected behavior
- Version information
- Steps to reproduce
- Cannot find Symbol error while using Lombok Annotations. #1449
- Comments
- Lombok/Mapstruct problem: Cannot find symbol #1270
- Comments
- How to Resolve The Cannot Find Symbol Error in Java
- Introduction to Symbol Tables
- Cannot Find Symbol Error
- What Causes the Cannot Find Symbol Error
- Cannot Find Symbol vs Symbol Not Found vs Cannot Resolve Symbol
- Cannot Find Symbol Error Examples
- Undeclared variable
Doesn’t compile with Gradle 5 RC #1945
Short description
Doesn’t compile with Gradle 5 RC
Expected behavior
Version information
- IDEA Version:
IntelliJ IDEA 2018.3 EAP (Community Edition)
Build #IC-183.4284.36, built on November 7, 2018 - JDK Version: 11.0.1
- OS Type & Version: macOS 10.14.1
- Lombok Plugin Version: v0.22.IDEA-EAP
- Lombok Dependency Version: 1.18.4
- Gradle Wrapper Version: gradle-5.0-20181112000030+0000
Steps to reproduce
None of the Lombok annotations work. All of the following are red.
The text was updated successfully, but these errors were encountered:
this work for me with gradle 5.0 release
@z0mb1ek What works — command line build works? Does IntelliJ work? Do you’ve a sample project that you can share?
Same problem for me with gradle 5.0 RELEASE.
Command line works, but intellij not.
I can fix it be changing the dependency to compile instead of compileOnly
Disclaimer: I’m not a project member and I’m not gonna fix it; I just hope that answering my questions could help those who will.
@mmoayyed No idea, but isn’t it a problem of the plugin? If so, then please use the proper issue tracker as it’s a separate project.
Update: @asarkar Apologies, I totally missed the link.
Otherwise, some information is needed about where it broken. Was it gradle 5.0 or was it Lombok 1.18.4? IOW what related versions do work?
@Maaartinus, did you see that in the original problem description, I’ve put a link to the IntelliJ plugin issue tracker, who claimed that the problem isn’t on their end? This sort of finger pointing isn’t representative of adult coders; someone needs to own the problem, and stop the buck from passing around. That doesn’t mean they must fix it immediately, but at least take responsibility.
@randakar I didn’t say @Maaartinus should pick up this ticket; I’m sure he can speak for himself, so I’ll instead focus on what you called out.
Lombok docs that you referred to seem to be outdated, which is somewhat clear from the heading «Gradle v2.12 and up».
See this discussion in Gradle forum. Gradle 5 onwards, Lombok needs to be registered as an annotation processor.
@asarkar have you retried since the first release of Gradle 5 ? Personally my project compiles correctly but my IDE (intellij) cannot resolve lombok’s annotation anymore. So I think there might be a problem with the plugin as you stated in your first issue.
by the way it builds correctly by using
but there are no reasons why it would not work with compileOnly , which worked correctly in Gradle 4.7+.
by the way it builds correctly by using
but there are no reasons why it would not work with compileOnly , which worked correctly in Gradle 4.7+.
Please check your final artifact. I use Lombok in a Spring Boot project and if I change from «compileOnly» to «Implementation» Gradle 5 includes Lombok JAR in /BOOT-INF/lib as runtime dependency.
probably related and caused by this one https://youtrack.jetbrains.com/issue/IDEA-201974, latest RC — works for me. (mind the caches)
@risbarov indeed, implementation is not a viable solution
IntelliJ IDEA 2018.3 EAP is working for me as well.
So this issue here is not related to Lombok and could be closed, right?
I think this is still a problem.
Using gradle 5.0 (release) together with lombok 1.18.4 does not compile.
Task :compileJava FAILED
/home/travis/build/LarsEckart/gradle5lombok/src/main/java/gradle5lombok/App.java:16: error: cannot find symbol
log.info(«logging Hello World»);
^
symbol: variable log
location: class App
1 error
FAILURE: Build failed with an exception.
When i downgrade to gradle wrapper 4.10.2, it compiles.
hm, ok, I had a close look at your project and one difference I spotted was that you not only declare lombok dependency as compileOnly, but also additionally as annotationProcessor dependency. When adding that line to my project, it indeed works. Will have to have a closer look at gradle documentation about annotation processors.
Thanks a lot for getting back to me and resolving this issue. Can also update my colleagues then who came to me today with the same problem 😉
I think this is still a problem.
Using gradle 5.0 (release) together with lombok 1.18.4 does not compile.
Task :compileJava FAILED
/home/travis/build/LarsEckart/gradle5lombok/src/main/java/gradle5lombok/App.java:16: error: cannot find symbol
log.info(«logging Hello World»);
^
symbol: variable log
location: class App
1 error
FAILURE: Build failed with an exception.
When i downgrade to gradle wrapper 4.10.2, it compiles.
Same as here. Did anyone discover why it does not compile in Gradle 5?
I think this is still a problem.
Using gradle 5.0 (release) together with lombok 1.18.4 does not compile.
https://github.com/LarsEckart/gradle5lombok
both on my laptop and travis-ci I get:
Task :compileJava FAILED
/home/travis/build/LarsEckart/gradle5lombok/src/main/java/gradle5lombok/App.java:16: error: cannot find symbol
log.info(«logging Hello World»);
^
symbol: variable log
location: class App
1 error
FAILURE: Build failed with an exception.
When i downgrade to gradle wrapper 4.10.2, it compiles.
Same as here. Did anyone discover why it does not compile in Gradle 5?
also have the problem, lombok 1.18.6 does not work on the console with Gradle 5.x.
I am also interested in the solution, for me
does not work in the console
. error: cannot find symbol
I am facing the same issue JDK 11, Gradle 5+ and lombok 1.18.6 with Eclipse.
Eclips plugin seems fine but command line is broken.
I have exact same problem as @ingoschaal
@ingoschaal and @hiteshbargujar, are you using the literal string $lombokVersion in your build.gradle file or did you replace it with your actual Lombok version? (Maybe you have solved this already.)
I initially had compilation issues on the command line, using the gradle wrapper (gradlew), after simultaneously upgrading from Gradle 4.10.* to 5.4.1 and from Lombok 1.18.4 to 1.18.6. When I added annotationProcessor ‘org.projectlombok:lombok:1.18.6’ in the dependencies section, this solved my compilation issues. (Looking at the changelog for Lombok and also at previous comments here (and at the title of this issue), my compilation issues appear to have been more to do with configuring Gradle correctly than with changing the Lombok version.)
@asarkar suggesting that the maintainers of an open source project are not ‘adult coders’ or are ‘passing the buck around’ is not acceptable. I understand that you may feel frustrated that stuff breaks and you now need to do extra work, whilst all you were doing was upgrading a few tools and libraries to newer versions. That doesn’t give you the excuse to make demands.
@ingoschaal @hiteshbargujar please note @RohanTalip ‘s comment; the gradle docs don’t reference 2.12 anymore, we fixed a bunch of gradle things, I read multiple reports that all is well, so I’m closing this. If you still have issues, open a new bug report and give us A LOT more information and something to allow us to reproduce the issue.
@rzwitserloot whatever is said is backed by evidence, so it’s true. Also, the same comment that you referred to also says “that doesn’t mean they should fix it immediately”, so no demand was made. What is not acceptable is you calling people out wrongly.
I understand that it must feel good to exercise you commit privilege and close the ticket, but you haven’t provided any solutions. You simply asked the reporters of this problem to open another ticket for the same issue if it persists.
we solved it the easy way, we are deprecating the use of Lombok dependencies in our code. We are almost complete refactoring.
@ingoschaal and @hiteshbargujar, are you using the literal string $lombokVersion in your build.gradle file or did you replace it with your actual Lombok version? (Maybe you have solved this already.)
I initially had compilation issues on the command line, using the gradle wrapper (gradlew), after simultaneously upgrading from Gradle 4.10.* to 5.4.1 and from Lombok 1.18.4 to 1.18.6. When I added annotationProcessor ‘org.projectlombok:lombok:1.18.6’ in the dependencies section, this solved my compilation issues. (Looking at the changelog for Lombok and also at previous comments here (and at the title of this issue), my compilation issues appear to have been more to do with configuring Gradle correctly than with changing the Lombok version.)
annotationProcessor ‘org.projectlombok:lombok:1.18.6’ in the dependencies section,
thanks thats works
I had the same issues with Gradle 5.4.1 and lombok 1.18.1 (while everything worked fine under Gradle 4.10.2), and eventually found this, which solved the issues:
Источник
Cannot find Symbol error while using Lombok Annotations. #1449
I am getting below error while using the lombok.
cannot find symbol
[ERROR] symbol: method builder()
[ERROR] symbol: getXXXXXX()
below are the annotation, I am using.
Maven version is 3.5.0
Below is the pom.xml entries.
Please advise what is this issue?
The text was updated successfully, but these errors were encountered:
Was able to resolve my issue. Did not realize that variables declared final had no setter.
I got the solution of this problem. I had to remove -proc:none that was preventing the lombok annotation to be processed.
I got the solution of this problem. I had to remove -proc:none that was preventing the lombok annotation to be processed.
@mukeshkamboj Thanks Mukesh! I just tried every damn thing with my intellij. Your comment helped me to get rid of the issue.
Regards,
Bhargav
Love all, Serve all !
hi, where is the -proc:none located?
I got the solution of this problem. I had to remove -proc:none that was preventing the lombok annotation to be processed.
i don’t know but it solve my problem.
i have two classes use @builder to generate build method. but one is normal, another is abnormal,everything check is ok. but when i run mvn to compile my project, the error as fellow:
can’t not find the symbol method builder()
i try to replace the version of the lombok jar, but even through i make the version is latest, it’s not ok.
so, i try to import lombok per class that i reference.
Источник
Lombok/Mapstruct problem: Cannot find symbol #1270
Hi, I love MapStruct and Lombok, but I get a «cannot find symbol» error when compiling with Maven from command-line using Javac.
In some setups, it is the @Mapper annotation that cannot be found, in other setups it is the calls to the Lombok-generated getters/setters etc.
I have created a minimal test-project that demonstrates the error. Code, pom file, stacktrace, Java-version, Maven-version, dependencies etc are all described in the zip-folder files.
I am using maven-compiler-plugin version 3.6.1, mapstruct-jdk8 version 1.2.0.CR1 and lombok version 1.16.16. And the project is a spring-boot application.
Note that this issue resembles #841, which recommends to exlude the transitive mapstruct dependency pulled in from the dependency to springfox-swagger2. This, however, did not solve the problem.
This is the output from mvn clean verify :
The text was updated successfully, but these errors were encountered:
By downgrading the maven-compiler-plugin from 3.6.1 to 3.1 I got it to work.
I trimmed the attached pom further to pindown the problem, and this is the new pom (with the downgraded plugin version that makes it compile):
I will leave the issue open in case this is a bug — it is possible that I have missed this requirement in some documentation.
Thanks for the nice words. We are glad that you like MapStruct 😄 .
The problem is that you have only mapstruct-processor in the annotationProcessorPaths and only that dependency is passed to the javac compiler.
The annotationProcessorPaths is there only since 3.5 so it is really strange how the mapstruct processor is invoked. In any case in order to make it work correctly you have 2 options:
Add the lombok dependency to the annotationProcessorPaths as well. Then it will be picked up by the compiler and it should work.
Ad the mapstruct-processor jar to your pom as a provided dependency. You will have to remove the annotationProcessorPaths in that case and the compiler will pick up the processors from your dependency. The reason why we are suggesting to use the annotationProcessorPaths is because by doing that you won’t be able to use something from the mapstruct-processor module by accident. An additional reason to put it in the pom dependencies is this issue from IntelliJ (in case you are using InteliiJ 😄
You can also have a look at the mapstruct-lombok example from our repository.
I am going to close this issue as it is a problem in the configuration 😄
Источник
How to Resolve The Cannot Find Symbol Error in Java
Table of Contents
Introduction to Symbol Tables
Symbol tables are an important data structure created and maintained by compilers to store information associated with identifiers [1] in a given source code. This information is entered into the symbol tables during lexical and syntax analysis and is used in the later phases of compilation. As the declarations of classes, interfaces, variables, and methods are processed, their identifiers are bound to corresponding entries in the symbol tables. When uses of these identifiers are encountered in the source code, the compiler looks them up in the symbol tables and relies on this information for things such as verifying that a variable has been declared, determining the scope of a variable, and verifying that an expression is semantically correct with type checking. Symbol tables are also used for code generation and optimization [2].
A simplified representation of a symbol table entry (or simply, a symbol) in Java has the following format: . Given a global variable declaration like final double ratio; the corresponding symbol would then be .
Cannot Find Symbol Error
As its name implies, the cannot find symbol error refers to a symbol which cannot be found. While there are multiple ways and reasons this can occur, they all boil down to the fact that the Java compiler is unable to find the symbol associated with a given identifier.
The message produced by the compiler for the cannot find symbol error includes two additional fields:
- “symbol”—the name and type of the referenced identifier; and
- “location”—the specific class in which the identifier has been referenced.
What Causes the Cannot Find Symbol Error
The most common triggers for the cannot find symbol compile-time error include:
- missing variable and method declarations;
- out-of-scope references to variables and methods;
- misspelled identifiers; and
- omitted import statements.
Cannot Find Symbol vs Symbol Not Found vs Cannot Resolve Symbol
As different Java compilers use slightly different terminology, the cannot find symbol error can also be found under the terms symbol not found and cannot resolve symbol . Besides the naming, there is no difference between what these terms stand for.
Cannot Find Symbol Error Examples
Undeclared variable
When the Java compiler encounters a use of an identifier which it cannot find in the symbol table, it raises the cannot find symbol error. Consequently, the most common occurrence of this error is when there is a reference to an undeclared variable. Unlike some other languages that don’t require explicit declaration of variables [3], or may allow declaring a variable after it has been referenced (via hoisting [4]), Java requires declaring a variable before it can be used or referenced in any way.
Fig. 1(a) shows how an undeclared variable, in this case the identifier average on line 9, results in two instances of the cannot find symbol error, at the positions where they appear in the code. Declaring this variable by specifying its data type (or, alternatively, inferring its type with the var keyword in Java 10+) resolves the issue (Fig. 1(b)).
Источник
I am using below setup in build.gradle.
dependencies {
classpath ‘io.freefair.gradle:lombok-plugin:2.9.5’
}
lombok {
config[‘lombok.log.custom.declaration’] = ‘com.xxx.yyy.zzz.core.logging.Logger com.xxx.yyy.zzz.core.logging.LoggerFactory.getLogger(TYPE)(TOPIC)’
}
dependencies {
annotationProcessor ‘org.projectlombok:lombok:1.18.20’
implementation group: ‘org.projectlombok’, name: ‘lombok’, version: ‘1.18.20’
}
I could see the below entries on the autogenerated lombok.config file
This file is generated by the ‘io.freefair.lombok’ Gradle plugin
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
lombok.log.custom.declaration = com.xxx.yyy.zzz.core.logging.Logger com.xxx.yyy.zzz.core.logging.LoggerFactory.getLogger(TYPE)(TOPIC)
My Sample Code
import lombok.CustomLog;
@CustomLog
public class TestCustomLog {
public void test() {
log.info(«Hello World»);
}
}
Exception:
error: cannot find symbol
log.info(«Hello World»);
^
symbol: variable log
location: class TestCustomLog
IDE Ver: INTELLIJ ULIMATE 2020.3
JDK Ver: 8
There are other lombok annotation which I have used and they work fine.
xxx.yyy.zzz — this is the package to our in-house logging framework.
Это не будет проблемой ОП, но для всех, кто попытается многое без успеха:
У меня были похожие симптомы. Всякий раз, когда я строил после mvn clean
, он бы не нашел log
или getXYZ()
или builder()
, или что-нибудь.
[ERROR] symbol: variable log
[ERROR] location: class com.example.MyClass
[ERROR] /Path/To/Some/Java/src/main/com/example/MyClass.java:[30,38] cannot find symbol
[ERROR] symbol: method builder()
[ERROR] location: class com.example.MyClass
Прочитав каждый ответ, который я смог найти о проблемах QueryDSL/JPA/Hibernate/Lombok/IntelliJ/Maven, но безрезультатно, я понял, что виновником был один статический импорт @Getter
метод, который был аннотирован в статическом поле.
Весна 1.15.14.РЕЛИЗ, Intellij 2019.1.1
@SpringBootApplication
public class BarApplication implements ApplicationContextAware {
@Getter
private static ApplicationContext applicationContext;
// ... start Spring application, and grab hold of ApplicationContext as it comes past
}
import ...
import static BarApplication.getApplicationContext;
@Slf4j
public class IMakeItAllFail {
public IMakeItAllFail() {
log.info("{}", getApplicationContext());
}
}
@Slf4j
public class Foo {
Foo() {
log.info("I fail to compile but I have nothing to do with the other classes!");
}
}