Search code examples
eclipsemavenm2eclipsem2emulti-module

Multi-module Maven with Profile in Eclipse Doesn't Resolve Dependencies on Children


For my setup, I have profiles defined in my ~/.m2/settings.xml, where the profiles define some project-specific repositories. From the command line, I can successfully build the projects using -PprofileHere. However, the profile isn't enabled automatically (i.e. activeByDefault is not set to true for the profile).

In Eclipse 4.5.1 (Mars 1) with m2e 1.6.2.20150902-0002, I import the projects using ImportMavenExisting Maven Projects. I select the parent project and Eclipse imports them. The children projects are imported, but as expected, their dependencies aren't correctly resolved. To attempt to fix this, I select the parent project, right-click MavenSelect Maven Profiles... and select the correct profile for the parent. I then do the m2e tango by trying various combinations of the following:

  • Cleaning and rebuilding the project (ProjectClean...)
  • Updating the parent project (Right-click, MavenUpdate Project...)
  • Updating the children projects (ditto)
  • Restarting Eclipse

Eclipse continuously shows the dependencies unresolved on the children projects when viewing the children pom.xml's or opening a class in a child module with unresolved dependencies. The only workaround I've found is by enabling the profile automatically in my ~/.m2/settings.xml. Then and only then does Eclipse properly resolve the Maven dependencies.

What am I doing wrong when originally importing / configuring projects in Eclipse?


Solution

  • How it worked for me in a sample project providing the same scenario: make Eclipse use a profile by default for a Maven build.

    • Right click on the concerned project > Properties > Maven
    • Type your profile there, it will be used by Eclipse during the build

    enter image description here

    I never used this option, but apparently its purpose should suit your need.