0

I have imported an existing manven project into my eclipse new workspace which I downloaded from github. On maven install I get a BUILD SUCCESS but the red cross on the project never goes. This issue has been raised previously : link1, link2

Most of the solutions tell about update project and any number times I do update project, It doesn't solve the problem.

The other solution is about having lombok plug-in because I noticed that many of the getter and setter methods are causing problems(absent). The lombok plug-in is to auto-generate them....I have it in my pom.xml but still the problem persists. In fact the problems tab shows a 100 errors like the samples below:

__ cannot be resolved to a type

The blank final field API_KEY may not have been initialized

The constructor APNSService(ApnsService) is undefined

How to solve this issue?

Any help is appreciated.

Note: I am running the maven project on jdk1.8.

Community
  • 1
  • 1
Eswar
  • 1,201
  • 19
  • 45
  • have you tried cleaning the project from under the project tab in tool-bar? – Ankur Aug 30 '18 at 06:55
  • you get a BUILD SUCCESS while the build isn't finished? weird. Either way: cannot be resolved to a type means that a dependency (or class) can't be found, might be caused by unfinished build. check whether that field is initialized, if not, do so. you are somewhere calling a constructor that does not exist. Lombok generated methods won't appear unless that step of the build actually succeeds, so you'll have to fix the build issues you have, that should fix itself once you do – Stultuske Aug 30 '18 at 06:56
  • @Stultuske If I start initializing stuff, there are so many places to do..maven install gives me BUILD SUCCESS and still Lombok doesn't generate the methods?? – Eswar Aug 30 '18 at 07:01
  • @Ankur cleaning doesn't help, I have done it any number of times and yet not fixed. – Eswar Aug 30 '18 at 07:03
  • do you run your mvn install through eclipse or command line? – Stultuske Aug 30 '18 at 07:06
  • @Stultuske running maven install through eclipse – Eswar Aug 30 '18 at 07:09

1 Answers1

1

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 compiling in Eclipse but not in maven, or vice versa.

Installation instructions for Eclipse can be found here.

UPDATE: 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). You could also try Eclipse Oxygen instead of Photon (there are sporadic reports of problems with Photon; however, there seems to be no general issue in combination with Photon).

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.

Jan Rieke
  • 7,027
  • 2
  • 20
  • 30
  • In pom.xml, the lombok specification is there(version-1.16.6). But the installed plugins doesn't show lombok yet I get a BUILD SUCCESS....How do I solve this – Eswar Aug 30 '18 at 07:16
  • Did you check the "About Eclipse" dialog, as described in the installation instructions? Which lombok version does Eclipse report there to be installed? PS: The "Build success" is probably from maven, and as I said, the maven compilation process has nothing to do with the Eclipse compilation. – Jan Rieke Aug 30 '18 at 07:55
  • I no more get the problem with getter and setter mehods, when changed the goal to install in the run configurations. But the blockquoted problems still persist.. – Eswar Aug 30 '18 at 13:22
  • Again: What does _Help_ -> _About Eclipse_ say about the installed lombok version? There should be a text directly in that dialog saying something like _"Lombok v1.18.3 "Edgy Guinea Pig" is installed."_ If there is no such text, you have to install the Eclipse lombok plugin. – Jan Rieke Aug 30 '18 at 14:41
  • I couldn't find any text as mentioned, for that matter I did not find any plug-in information in the location you specified but I see something like in this link: https://howtodoinjava.com/automation/lombok-eclipse-installation-examples/ I just had a look the imports are there but the getter and setter methods still seem to be unresolved.. – Eswar Aug 31 '18 at 04:51
  • Could it be some problem with the version compatibility of lombok? Should I shift to higher versions or lower versions?? – Eswar Aug 31 '18 at 05:00
  • Then lombok is definitely not installed correctly in your Eclipse, and that is the problem. I don't think another lombok version will help, because the installation process did not change recently. But you should try installing lombok to a clean Eclipse installation, even before you add any projects. Maybe try Eclipse Oxygen (and not the latest Photon). Then re-check the "About" dialog. – Jan Rieke Aug 31 '18 at 05:57
  • thank you. Using oxygen and following https://projectlombok.org/setup/eclipse solved the issue. Accordingly update the answer including why using oxygen should solve the problem and it will be accepted. – Eswar Aug 31 '18 at 06:32
  • please add the reason as to why using eclipse-oxygen should solve the problem and not eclipse-photon – Eswar Aug 31 '18 at 08:08
  • It worked for eclipse-photon too, I think the fundamental problem was that the eclipse lacked lombok. When I saw the imports happening I misunderstood that this must be because the eclipse has lombok. But now I get it, independent from your project, the eclipse must also have it installed and it will show up in "About eclipse". – Eswar Aug 31 '18 at 09:35