I am not able to use any of the lombok annotations in Intellij, it works fine in Eclipse.
So far, I have done the following things:
Added lombok dependency in eclipse
Installed the lombok plugin
Enabled annotation processing
However, I cannot use any of the lombok annotations, eg: using #Builder gives error because import lombok.Builder does not exists.
I am using IDEA 2018.2.1 CE
Any ideas, what am I doing wrong?
MVN dependency:
Can see the dependency resolved:
Can see the lombok plugin:
Annotation processing enabled:
EDIT:
Following code gives an error, basically i cannot use import lombok because somehow I lombok is not available:
import lombok.Builder //Error, Cannot resolve Builder
#Builder //Gives error, cannot resolve symbol Builder
public class Employee{
private int id;
private String name;
}
From your images, it seems like you have submodule temp, it can be the problem
The pom.xml is for project buildertest, not temp
If you want to have submodule, you should also set it as Maven project and have another pom.xml
Related
I have 2 classes in a Eclipse project.
package com.example;
import lombok.Getter;
import lombok.experimental.Accessors;
#Accessors(fluent = true)
#Getter
public class MyBean {
private String value = "aaa";
}
package com.example;
public class MyClass {
public static void main() {
System.out.println(new MyBean().value());
}
}
After building, Eclips reports "the value of the field value is not used" for MyBean class and "The method value() is undefined for the type MyClass" even though Eclipse's content assist shows MyBean#value() method, there are no warnings before building, and compilation, execution both are finished successfully.
So I guess Lombok works properly and the problem is Eclipse doesn't recognize Lombok.
Here are what I tried and found.
attaching lombok.jar to Eclipse and checking eclipse.ini
cleaning and rebuild the project
removing Lombok dependency from maven local repository then reinstall
the problems only occur in this project. Eclipse handles other projects with lombok properly (and all projects belong in the same workspace).
I cannot reproduce these problems in other projects.
Any ideas?
Finally, the problems are solved by just creating new project and moving all sources and resources to it.
It seems that Eclipse's project configurations were broken I don't know why.
I install lombok on eclipse(java -jar lombokxxxx.jar) and the problem disapear.
Lombok API Configuration
Note: Lombok version may change. Present we are using 1.18.24
Goto -> C:\Users\Udaykiran.Pulipati.m2\repository\org\projectlombok\lombok\1.18.24
A Lombok configuration window will open > Click on Specify location button
Select eclipse.exe root folder where it is located(installed)
Selecting eclipse.exe root folder > D:\eclipse\jee-2021-06\eclipse
Click on Install / Update button in Lombok configuration window
Click on Quite Installer
Restart Eclipse IDE
It's seem lombok annotation is not working.
import lombok.Getter;
import lombok.RequiredArgsConstructor;
#Getter
#RequiredArgsConstructor
public class HelloResponseDto {
private final String name;
private final int amount;
}
and here is output
> Task :cleanTest UP-TO-DATE
> Task :compileJava FAILED
C:\Users\tahun\IdeaProjects\spring-tutorial\src\main\java\org\example\springboot\web\dto\HelloResponseDto.java:10: error: variable name not initialized in the default constructor
private final String name;
^
C:\Users\tahun\IdeaProjects\spring-tutorial\src\main\java\org\example\springboot\web\dto\HelloResponseDto.java:11: error: variable amount not initialized in the default constructor
private final int amount;
I'm working with Intellij so I also checked
Settings > Compiler > Annotation Processors > Enable annotaion processing
and i also add compile('org.projectlombok:lombok') in my build.gradle
Is there any solutions?
==more==
I also installed lombok plugin.
You need to install lombok plugin to Intellij. You can use following url to download.
Lombok Plugin
Install the needed plugin for Lombok...
Lombok is not supported out of the box.
You can add the lombok plugin - https://plugins.jetbrains.com/plugin/6317-lombok/
Go to Setting --> plugins and search for lombok and add the plugin.
Restart and check. IntelliJ should not report any error of lombok.
This problem is resolved, please have a look into the below StackOverflow URL
Adding Lombok plugin to IntelliJ project [duplicate]
Lombok annotations do not compile under Intellij idea [duplicate]
Can't compile project when I'm using Lombok under IntelliJ IDEA
Download IntelliJ Plugin Lombok IntelliJ plugin
its very easy to configure lombok in IntelliJ using below steps:
1.Go to Setting --> plugins and search for lombok and add the plugin.
2. restart the intelliJ
3. check if working or not , if still not working then restart your system due to some time not able to configure new plugin properly.
I'm trying to run sample Spring boot application and I'm facing problem with entities that are marked as #RequiredArgsConstructor on my IDE. I'm using latest intelliJ IDEA (14.1) over java 1.8. There's an error marked on IDE when I tried to initialize the entity with constructor arguments.
E.g. It would be showing "cannot resolve symbol" for following line.
itemRepository.save(new Item("MacBook Pro"));
My entity would be as follows.
#Entity
#Data
#RequiredArgsConstructor
public class Item {
private #Id #GeneratedValue Long id;
private final String description;
Item() {
this.description = null;
}
}
Apart from IDE error project builds and runs properly.
The sample project you are running uses Lombok, a library which can generate a lot of boilerplate code for you (such as getters and setters) based on annotations (e.g. #RequiredArgsConstructor). This is useful, but because the code is generated during compilation, the IDE doesn't see it and therefore shows errors.
You must install Lombok plugin to make IntelliJ aware that the constructor actually does exist, but is generated during compilation. Then the errors will go away.
You can also take a look at this post for more details about how Lombok works under the hood.
I'm using Lombok to add logging to my Java applications. I've been using this for some time, but since I upgraded my IDE from IntelliJ 13 Community edition to 14 Ultimate, I get the following compile errors (using maven):
error: log has private access in SesameServer
This error originates in a subclass of SesameServer:
#Slf4j
public class AnnotatorServices extends SesameServer {
#Override
protected void initialiseRDFStoreManager(Series<Parameter> parameters) throws RepositoryConfigException, RepositoryException {
log.info("<< ------ Annotator Services ------- >>");
}
}
Of course SesameServer also uses the #Slf4j annotation to add logging. The #Slf4j annotation adds the line:
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SesameServer.class);
to the class in which it is used (both SesameServer and AnnotatorServices where SesameServer.class is of course replaced by AnnotatorServices.class).
Apparently the compiler thinks I want to use the log variable from SesameServer instead of AnnotatorServices (both classes have variables with the same name).
How can I prevent this problem, i.e. that the SesameServer.log is used instead of AnnotatorServices.log?
NOTE: This still comes up for anyone else googling this error message; so adding my fix hope this helps.
I had a similar issue after reopening a project from pom.xml.
Since my parent class SesameServer was already built in a different module and used a dependency; when I compiled my AnnotatorServices I also saw the error: log has private access in SesameServer
To fix it I just had to turn on Annotation Processing for the module containing AnnotatorServices.
In IntelliJ Community 2017.1.6 the check box was found under:
File -> Settings
"Build, Execution Deployment -> Compiler -> Annotation Processors"
Tick the "Enable annotation processing"
Following steps worked for me
Install Lombok Plugin in Settings=>plugins under Marketplace search for Lombok and install.
Then in IntelliJ Community 2017.1.6 go to File->Invalidate Caches/ Restart and click on both.
Did the trick for me. All the best.
Make sure your subclass is also annotated properly with #Slf4j.
Update your lombok plugin. Sometimes idea does not display the new updates so goto settings => plugins and search for "lombok"
Click "update" and restart idea
I'm trying to lombok for the first time. I tried to follow directions as best as possible, but when I look at my compiled classes (using a decompiler) they do not have any of the generated getters or setters.
My installation steps:
Downloaded lombok 1.14.8 and ran java -jar lombok.jar. It added lombok to eclipse. Restarted Eclipse (-clean the workspace too). If I check my About Eclipse page, I see:
"Lombok v1.14.8 "Branching Cobra" is installed. http://projectlombok.org/"
Added lombok to my pom.xml:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<version>1.14.8</version>
</dependency>
Maven->Update Project. Project->Clean
My Lombok'ed java class:
import lombok.Getter;
import lombok.Setter;
public class User extends BaseCouchDbDocument {
public User() {
// TODO Auto-generated constructor stub
}
#Getter #Setter
private String name;
}
When using the code completion in Eclipse, I see User.getName() and User.setName() appear. However, if I try to use the getters or setters, I get a compile time error that no such method exists. When I look at the generated .class file, I only see the following:
public class User extends BaseCouchDbDocument
{
private String name;
}
Similarly, if I run mvn compile from the command line, I get the same class output.
What I find odd is that the #Getter and #Setter annotations are removed, implying that there is some processing occurring on my files. But the getters/setters aren't being generated.
Am I doing something wrong? I'm using Java 7 on a Mac.
After posting this, I ran across a bug report that indicated it was a problem with AspectJ.
Indeed, I am using AspectJ with my project, and it is causing conflicts with Lombok. Removing AspectJ now shows properly generated setters/getters.
This obviously does not "resolve" the issue, but at least points me in the right direction. I created another issue here to track this specific problem.
Hopefully this can help someone else in the future as well.