lombok annotation is not wokring in intellij19.3 - java

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.

Related

Eclipse reporting "the value of the field is not used" warning even though Lombok enable

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

Getting compilation error while using #Slf4j in Lombok in Eclipse

Building the project using gradle in eclipse after Using #Slf4j annotation of lombok is throwing below error :
Task :compileJava FAILED
error: cannot find symbol
log.trace("logging now");
^
symbol: variable log
But it is generating the .class file with the log variable correctly : private static final Logger log = LoggerFactory.getLogger(NetsuiteWebSecurityConfig.class);
There is no problem with the #Data lombok annotation. It is generating getters/setters in .class file and also not throwing any error .
Note : i referred this Cannot make Project Lombok work on Eclipse (Helios) for lombok installation . I can say lombok is working because it is generating the code in .class file . Not sure why it is failing while giving gradle build
I installed lombok correctly and set the annotations processor. But still nothing worked . What i have done is created a new folder at another place and cloned my git repository freshly there. To my surprise it worked . Dont know how , but the trick worked .

Lombok not working with Intellij

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

"log has private access" error when using Slf4j annotation and Lombok in IntelliJ

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

importing NotNull or Nullable and Android Studio won't compile

When I add #NotNull or #Nullable annotations to a parameter Android Studio automatically helps me with adding /lib/annotations.jar and importing
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable;
But after this, the project won't compile. If I also remove the annotations but keep the import statements the project still won't compile. But if I remove the import statements for NotNull and Nullable the project compiles fine!
Android Studio gives a generic error:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Running gradlew compileDebug from cmd gives a slight hint:
:Bugtester:compileDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
So I checked my environment variables and they are set as:
JAVA_HOME=C:\Program Files (x86)\Java\jre7
JDK_HOME=C:\Program Files\Java\jdk1.7.0_21\
Anyone got any idea for this? (I'm new to both java and android programming)
I guess, the right way is using original JetBrains library from MavenCentral repository in your build.gradle dependencies (latest available version in this example):
dependencies {
implementation 'com.intellij:annotations:+#jar'
...
}
You can also use android's own #NonNull & #Nullable:
Add the following to build.gradle:
dependencies {
...
// For #Nullable/#NonNull
compile 'com.android.support:support-annotations:+'
}
Go to File / Setting → Project Settings → Inspections and search for "nullable".
In Constant conditions & exceptions and #NotNull/#Nullable problems, click Configure annotations and select Android's annotations.
You may also want to check out Suggest #Nullable annotations… under Constant conditions & exceptions, or possibly tweak other options.
For using Android support anotation like - #Nullable, #NonNull etc.. In your project must be imported android support annotations library. Just add this line to dependensies in gradle file
dependencies {
compile 'com.android.support:support-annotations:+'
}
And import package to class.
For using #Nullable annotation:
import android.support.annotation.Nullable;
For #NonNull
import android.support.annotation.NonNull;
More info you can find here Android developers
At the moment, there is no NonNull/Nullable annotations in the Android API or in the support library. You also cannot use the IntelliJ one since they are not on the compilation classpath when building with Gradle.
However, you can easily create your own. It's very simple:
#Documented
#Retention(RetentionPolicy.CLASS)
#Target({METHOD,PARAMETER,LOCAL_VARIABLE,FIELD})
public #interface NonNull {
}
Once this is down, you can configure IntelliJ (or Android Studio) to recognize this one (and the matching #Nullable) to be the default annotation used for Null-checks.
To do this, go in the IntelliJ preferences, under Inpections, and then find the #NotNull/#Nullable problems entry under Probable Bugs in the inspection tree.
Select the item, and in the bottom right you'll have a button to "Configure Annotations". This will allow you set your own annotations as the one intelliJ will use for this inspection.
In 2015, you would have used annotations from android.support.annotation package. I am just not sure when they added them as in the docs there isn't that typical sentence "Added in API level X" and I don't feel like reading blogs, etc. >]
import android.support.annotation.NonNull;
...
public void fooFighter(#NonNull Object honeyBunny){
...
}
I am facing that problem for gradle-5.1.1 - Android Studio 3.4 and the error like that - Compilation failed; see the compiler error output for details. Execution failed for task ':app:compileDebugJavaWithJavac'. etc. In this case I use
implementation 'org.jetbrains:annotations:16.0.2'
and above all error will be clear.
Just import androidx.annotation.Nullable for that purpose
The best way is to use the maven dependency
set the repository path, by adding
repositories {
maven {
url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases"
}
}
add the dependency
dependencies {
compile 'org.jetbrains:annotations:7.0.2'
}
PROFIT!
For Maven add dependency:
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.1</version>
</dependency>

Categories

Resources