Home > Back-end >  Eclipse settings for maven modules
Eclipse settings for maven modules

Time:11-11

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.

CodePudding user response:

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).

  • Related