4

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?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
coastalhacking
  • 307
  • 2
  • 13
  • You appear to do everything right. Both Eclipse and m2e are up-to-date. Did you try to update your Maven Settings by going to Windows > Preferences > Maven > User settings" and clicking "Update settings" a couple of times and then a random combination of Apply and OK? Try to add this to your m2e dance. – Tunaki Dec 12 '15 at 17:29
  • Just tried @Tunaki, didn't work. – coastalhacking Dec 12 '15 at 17:36
  • I personally have never used the "Select Maven Profiles..." feature... Maybe you just hit a m2e bug. You should try to get in touch with the m2e team. – Tunaki Dec 12 '15 at 17:37
  • @Tunaki Ok, seems like a bug. I'll see what the m2e team states. Hopefully it's already known... – coastalhacking Dec 12 '15 at 17:47
  • I know it doesn't answer the question, but just wondering: why such a non-active-by-default profile then? It means your build is not fine without activating that profile, which goes a bit against maven best practices (I shouldn't know about that profile and I should be able to build it simply executing mvn clean install). – A_Di-Matteo Dec 12 '15 at 18:00
  • 1
    Added bug [484279](https://bugs.eclipse.org/bugs/show_bug.cgi?id=484279). Time will tell. – coastalhacking Dec 13 '15 at 01:06
  • 1
    @Tunaki - turned out not to be a bug; rather it's by design. – coastalhacking Dec 13 '15 at 21:32

1 Answers1

2

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.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128