0

Our enterprise team maintains a settings.xml file that defines various profiles that development projects can use with Maven to build their artifacts and install them in a repository. The expectation is that each project in Jenkins would define a -P parameter with the desired profile specified.

Here is my issue: The profile I need to use specifies a repository that is normally not visible to my project (a staged release repository), so anything in that repository cannot be depended upon without that profile being active. I need a way to activate that profile defined in settings.xml in my project's pom.xml file. Otherwise, when looking at my project in Eclipse, errors are shown in the pom.xml that dependencies cannot be resolved because the profile isn't active to make the repository visible.

Is there a way to activate a settings.xml defined profile in a pom.xml file? Alternatively, is there a way to tell Eclipse to always activate a profile for a particular project?

cneff
  • 388
  • 6
  • 15
  • Why can't you activate the profile on the command line? I'm not sure I understood the problem. – Tunaki Jan 29 '16 at 15:00
  • Define build profiles in the settings.xml is never a good idea and in particular not in Jenkins. Jenkins has a good plugin: [Config File Provider](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin) which handles this perfectly. furthermore it sounds like you should use a repository manager for your development... – khmarbaise Jan 29 '16 at 16:11
  • @khmarbaise : I'll let the enterprise folks know about the plugin, thanks. And we are using a repository manager. My problem is the visibility of release candidates as dependencies to other projects in development. – cneff Jan 29 '16 at 16:42
  • @Tunaki : The problem is that Eclipse doesn't have a command line to specify during its normal workspace build. I did find a solution, it is in my self-provided answer. – cneff Jan 29 '16 at 16:44
  • @cneff You're wrong, it does ;). Create a custom Maven build (Run > Maven build...) and you have a textbox: "active profiles" that you can list. Then you can make that build configuration generic with the `${projectloc}` placeholder. Then you just need to select the project and run the configuration! – Tunaki Jan 29 '16 at 17:11
  • @Tunaki : I am not being clear. I am not talking about when I tell Eclipse to build the project using Maven. I am talking about when the Eclipse m2e plugin builds a project and reports any problems with the `pom.xml` file. This doesn't require a run configuration at all. – cneff Jan 29 '16 at 18:32
  • @cneff I see. That's a completely different problem yeah... Then I agree, I don't think there's a way to do it globally... – Tunaki Jan 29 '16 at 18:33

2 Answers2

2

You can use the activateByDefault tag to specify a default profile to use:

    <profile>
           <id>ProfileToActivate</id>
           <activation>
             <activeByDefault>true</activeByDefault>
           </activation>
    </profile>
Revive
  • 2,248
  • 1
  • 16
  • 23
  • That works where the profile is defined, which in this case is the `settings.xml` file, which I don't have access to change. Additionally, that would make it active for everyone, when I'm the only project that wants it active all the time. – cneff Jan 29 '16 at 16:39
2

After more research, I found a project specific Maven property in Eclipse where I can set the active profiles. You can set this by right-clicking on the project, select "Properties", and select "Maven". You are presented with a text entry box for "Active Maven Profiles (comma separated):".

That solved my problem.

I was looking for a more global solution in Eclipse rather than at the project level. But this seems to work.

cneff
  • 388
  • 6
  • 15