0

I cloned the maven project to my local disk. The project has 3 modules as well as a parent project. i marked the 3 modules with the 3 colors-- the 4th, blue color is the project itself.

The project is running all fine on maven both on Eclipse and on command line. When i do a mvn install on Eclipse, the project is built and all the tests are run successfully -- i see the good old BUILD SUCCESS report of maven on Eclipse console.

The problem is -- the modules are all messed up. (this "messed up" is the best way i can put it for now.) Eclipse doesn't recognize the dependencies between modules and gives checked errors to some of the code that use outside dependencies.

At one place-- lombok @Getter is used in one class. import lombok.Getter; is seen by the compiler-- no checked error to that. but eclipse doesn't recognize the getter declaration of lombok, say getField() for the field field. i know this because : a) in the class itself-- gives a warning that .. the private field field isn't used. b) gives a checked error to getField() a reference from another class. Thought this might be an interesting example to how the dependencies are "working". i'm guessing one dependency that lombok is using is intercepted somewhere along the way to give this inconsistency.

Following is the project root directory structure on disk. (the 3 colors are the 3 modules, have to hide the names for confidentiality):

enter image description here

the 3 modules are defined in the pom.xml as follows:

enter image description here

i see the following in Eclipse project explorer:

enter image description here

so in the Project explorer, the 2 modules/tests (green & yellow) that have java dir, i.e. src/main/java appear twice. the orange module has only src/main/resources and no src/main/java.

In the second occurrences of the modules in the project explorer (the image above), there are no dependencies of any kind, not even Java itself and hence all those red dots all around (compiler errors). The first occurrences of modules have Referenced Libraries and no Maven Dependencies:

enter image description here

How to fix this project so that i can code and run in Eclipse? Just to pin down-- project configuration is all fine and it runs successfully on maven. the problem is Eclipse's own settings on it.

so far i tried the following:

  • made the project faceted and added Java as the only one to its facets
  • imported as Maven project -- File > Import > Maven > Existing Maven Projects
  • ran mvn eclipse:eclipse on its pom.xml

Wasn't even seeing the Build path before these.

i'd appreciate the help-- wore me out.
everyone else on the project is IntelliJ developer-- no workspace to compare with.

i've seen Importing Maven project into Eclipse and some other useful discussions.

i'm not sure whether i should post .project, .settings and some other file contents also. will do if necessary.

TIA.

ash__999
  • 161
  • 1
  • 1
  • 11
  • 1
    It looks like you only imported the parent pom.xml. But you also have to be import the modules as projects in Eclipse. Use _File > Open Projects from File System..._ or in the _Git Repositories_ view right-click and _Import Projects..._ to do this in one go. – howlger Nov 08 '21 at 07:58
  • @howlger you're right - hadn't imported the modules separately. now did - imported them then the project itself, all as Existing Maven projects. things changed a bit-- now seeing Maven dependencies for one. but the lombok dependencies i'm mentioning in the Q are as is – ash__999 Nov 08 '21 at 17:04
  • Did you install Lombok in Eclipse? – howlger Nov 08 '21 at 17:26
  • @howlger no, it's getting lombok from its parent pom. the dependency hierarchy on its pom.xml is showing 3 difft instances of the same lombok (same version/package). it's not a lombok-specific issue. in another microservice like this, it's getting slf4j from 2+ places, this time from difft repos (ch.qos.logback and org.slfj4...) – ash__999 Nov 08 '21 at 17:33
  • To have "recognize the getter declaration" in Eclipse (e.g. when editing Java files, using the incremental Java compiler of Eclipse) Lombok has to be installed into Eclipse. Having Lombok in the Java Build Path is not enough. See https://projectlombok.org/setup/eclipse – howlger Nov 08 '21 at 17:37
  • @howlger installed lombok (wasn't there) and verified it on `About Eclipse` window. but didn't help. and i have a similar issue on slf4j and maybe some other dependencies thru parent poms-- didn't check all yet. what's the best way to deal with Eclipse settings on module dependencies? how are they supposed to look ok Build path? i think you could help &that wd be great. i see a lot of Eclipse on your bio – ash__999 Nov 09 '21 at 15:10
  • @howlger - update on the last - lombok worked when i removed& imported again the project into the workspace :) write these as an ans and i'll accept. thx for your help! – ash__999 Nov 09 '21 at 16:07
  • Great is working now. I added as an answer. – howlger Nov 09 '21 at 17:29

1 Answers1

1

Make sure to not only import the parent pom.xml, but also the Maven modules as projects into Eclipse. To do this in one go, use

  • File > Open Projects from File System... or
  • in the Git Repositories view right-click the root folder and choose Import Projects...

Make also sure Lombok has been installed into Eclipse, otherwise Eclipse's own incremental compiler would not generate e.g. getter and setter methods that are defined by Lombok annotations. See the Lombok documentation of how to install Lombok into Eclipse. If you have installed Lombok after importing the projects, it might be that you need to do a Project > Clean... or close and reopen again the projects (via the right-click menu).

howlger
  • 31,050
  • 11
  • 59
  • 99