Eclipse Lombok annotations not compiled... Why? [duplicate] - java

This question already has answers here:
Lombok is not generating getter and setter
(25 answers)
Lombok problems with Eclipse Oxygen
(27 answers)
Closed 7 months ago.
I have a problem with my project.
It is an Spring CRUD RestFul API that expose services witch are providing Json datas.
I use JDK-7, Eclipse-Neon and Maven to code, build and the project is deployed into a JBossEAP 6.4 server.
Every thing is working well, the services are responding correctly.
So I decide to add Lombok, to reduce the boiler code and improve the readability of the code. By the way I used Lombok on an another project before and is worked fine.
Here is my problem, after including Lombok :
- When I make an ear using Maven (mvn clean install), everything is going well, the project deploy and work perfectly fine.
- When the project is built by Eclipse, the Lombok annotations (i.e.:#Data, etc) aren't included into the *.class. Consequently the ear deployed by Eclipse work fine BUT all the entity haven't any getter / setter and so on.
I know Eclipse is correctly configured because I haven't any warning associated to Lombok on my code, the outline view of eclipse show me generated methods.
Does anyone have a idea about this kind of problem?

You also must have the lombok plugin installed in Eclipse. (Note that this is something different from lombok being present in the project dependencies; you need both.) Furthermore, the version installed in Eclipse should be the same version that you have in your pom.xml. Otherwise strange compilation issues may occur, like code for some annotations not getting generated in Eclipse but in maven, or vice versa.
Installation instructions for Eclipse can be found here.
Check the "About Eclipse" dialog after the installation and an Eclipse restart. It must contain some text like "Lombok v1.18.3 "Edgy Guinea Pig" is installed.". If that is not the case, the lombok plugin is not installed correctly.
If the installation was not successful, you should try installing lombok to a clean Eclipse installation (even before adding any projects).
Explanation: Eclipse uses its own compiler (different from javac, which maven uses). Therefore, lombok also has to hook into the Eclipse compilation process, and therefore, Eclipse needs that lombok plugin.
Also note that Lombok annotation should never be present in the compiled class file, because the Lombok annotation processor removes them when generating the replacement code.

Related

How to get Eclipse to work properly with Gradle?

I am trying out Eclipse (because of frustrations with apparent version incompatibilities when upgrading another IDE), but it is proving equally problematic. This is a perfectly clean Eclipse installation (windows installer, second variant option), so it's an ootb issue.
(Simplified, theoretically-reproducable version): I downloaded two copies of a basic Java 17 project from Spring Initializr with no dependencies; one as Gradle, one as Maven (tester & tester2 respectively). The Gradle build shows errors where there are none, per the screenshot.
Note that in the one class in the besic, clean SpringBoot application, it sees the package name, the class name, and even the definition of String as being errors. But the same code in the Maven version is fine.
There are further issues that appear to derive from this, but keeping it simpleā€¦
At some point during my testing, some message/error showed up that suggested it was building with Gradle 6.8.3, which I believe would be a problem as that version doesn't support Java 16+. Eclipse is configured to use 7.3.
How do I tell Eclipse to recognise a valid project, so it can be worked with?

Java 11 Methods are not recognised in IntelliJ even after importing them correctly

I have started a new Java 11 Project with the newest Version of the IntelliJ IDEA Community Edition (IntelliJ IDEA 2018.3.5).
Everything seemed to work just fine for a while, but then some MethodCalls from imported modules were not recognised without any obvious reason. I've already tried invalidating the cache, but it did nothing. I'm also using maven 3.6.0 as I stumbled upon a post which suggested that the maven version that comes with said IDEA is not compatible with Java 11.
More specifically I tried using the method Optional.ofNullable() (same with of() or any other method of this class) which IntelliJ even proposed with AutoComplete. After auto-completion however IntelliJ seems to have forgotten it just now knew the method and proclaims: "Cannot find symbol: class ofNullable". The funny thing is: I can even Ctrl-Click Optional to be directed to the class and see that the method is actually there.
I'm at a loss. Has somebody experienced a similar problem?
I have solved this problem as follows for the Spring boot project with the Gradle build tool.
IntelliJ-Idea version should support Java-11.
Bigger scope to narrower scope
(IDE support --> Build tool --> Project setting --> Modules setting --> application run setting)
Add Java-11 SDK in Idea-IDE
Change Gradle JVM to Java-11
Change Project SDK and Language Level to Java-11
Change Module Language Level to Java-11
Change modules SDK to Java-11
Application run configuration to Java-11

Groovy 3 on Java 10 (Module-Info)

I'm currently trying to upgrade my Maven project to Java 10 but I'm having issues with the new module system.
One of my systems requires groovy for runtime code execution, so I depend on groovy-all (Version 3.0.0-alpha1).
When compiling however, I receive the following error (which results in a build failure):
module-info.java:[19,20] module not found: groovy.all
IntelliJ doesn't seem to have an issue with groovy.all while editing my module-info file. (However it seems to have issues with Lombok now?)
I recently came across this documentation for gradle which apparently could help fix my issue, however I'm using maven and right now I'm not sure where classpath.asPath comes from.

enum should not be used as identifier, since it is a keyword from source level 1.5 error in maven project

I created a maven project in myeclipse project as:
1) mvn clean install
2) mvn eclipse:myeclipse
I, then, imported project into myeclipse but I got loads of build errors like
enum should not be used as identifier, since it is a reserved keyword from source level 1.5...
I have used maven 3.2.5 for building and creating project with maven.
I am using myeclipse 10.7.0 with Java 1.7.0 JDK.
Please help.
You have a variable with name enum. Since enum is a reserved word in java 1.5 or higher you should rename the variable.
For more information you should add your code and the stacktrace.
From the error message, it looks like you have a project that is defined as a Java 1.4 (or earlier) project, but you have Java 1.5 code (enums) and that is producing the Java editor validation messages. Check your pom to see if it defines a Java source level. If so, ensure it is correct, or else define one, or change the java compiler level in the project properties. If you change the pom, make sure you right click on the project and select Maven4MyEclipse->Update Project.
Just an additional note. You do not need to run mvn eclipse:myeclipse to import a maven project and this is likely to result in a bad MyEclipse project as that Maven plug-in is not provided with MyEclipse. Instead, use Import->Maven4MyEclipse->Existing Maven Projects.
A further note is that 10.7 is no longer fully supported, it's recommended that you switch to the latest release (2015 Stable 1.0 or 2015 CI 11).
The problem has been solved by installing latest version of the eclipse. It automatically installed the m2e for myeclipse and compiled the projects without any errors.

Eclipse Luna not keeping code generated by Annotation Processing

I am running Eclipse Luna (4.4.1) under Ubuntu 14.10 (Utopic Unicorn) and have a project that uses annotation processing to validate certain forms in the code and generate utility code. In eclipse the code is not being generated.
First, the processors work perfectly with javac. Second the processors DO run in Eclipse. If I alter them to throw exceptions Eclipse reports that. Also if I provide the processors with malformed code (such as a getter/setter pair with different types) it reports the error properly (red squiggles, proper error message, whole nine yards).
No code appears in .apt_generated nor are class files generated.
I've tried disabling them and re-enabling them, starting a new project, tried it on a fresh install of Eclipse, changing the project version from 1.7 to 1.8 and back again, tried batch mode and not batch mode, changing the .apt_generated directory, double checked the permissions on .apt_generated, probably a few other things that I can't recall.
At this point I'm just running javac separately and thinking about making this our first Apache Ant or Maven project if that would help but I'd rather not quite at this juncture.
Anyone have any luck with code generation within Eclipse? Anything else to do or check?
Verify your project is set to actually use APT, as shown in https://www.eclipse.org/jdt/apt/introToAPT.php. Be aware those are project settings, not workspace preferences.
Make sure your potentially generated code is not deleted by some other part of your workflow. E.g. a second processor cleaning the directory that a first processor generated into.
Check that you are using a JDT and not a JRE both for running Eclipse as well as building your project.
Verify that org.eclipse.jdt.apt.core is part of your Eclipse installation, as that is the actual annotation processor integration for the JDT.
Verify your processor has a correctly filled file META-INF/services/javax.annotation.processing.Processor, pointing to the right class implementing the processor. Eclipse may ignore it otherwise.
That being said, I have used different annotation processors (like butterknife for Android) in Eclipse over the years and didn't run into such problems.
I had a similar problem with the AutoValue annotations not being processed with Eclipse 2019-3 with OpenJDK 11 as target runtime. In the Eclipse "Error Log" panel I saw this error:
java.lang.Exception: java.lang.UnsupportedClassVersionError:
javax/lang/model/element/ModuleElement has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Eclipse was running on an old Java 8 installation as indicated by Help -> About Eclipse IDE -> Installation Details -> Configuration. In my case, Eclipse found the JRE to run on on the PATH environment variable, see here. I forced Eclipse to use the OpenJDK 11 installation by adding the -vm argument to the Eclipse.ini:
-vm
"C:\path\to\OpenJDK\bin\server\jvm.dll"

Categories