Question

I have a lot of maven projects. I have two different global settings.xml for them which I need to merge. Both of them describes their repositories inside the profiles. I merged the two settings.xml by the mirrors and profiles tags. One of the profiles is activated by the activeProfile tag in settings.xml file.

I want to ask you, how I can change the active profile in the different projects? Can I select it in the project pom.xml file?

Thanks, Br, Stristi

Was it helpful?

Solution

This document describes how profiles can be activated: Introduction to Build Profiles.

You could activate profiles via environment variables, but if you have many projects, and want to apply profiles per-project basis, then it's a fault solution to change environment variable before each separate project build execution. If you are working with IDE, you can configure launch configuration to set the property for each project, and you have to configure the correct mvn run command within a continuous integration for each project. However, that would make it impossible to build an aggregated build consisting of different projects that should be activated by different profiles.

A possible workaround (which doesn't seem to be elegant, but I'm pretty sure it will work) is activating profiles based on file presence, and managing such 'marker files' for different projects to activate the required one. For example:

<profiles>
  <profile>
    <activation>
      <file>
        <exists>.profile-A</exists>
      </file>
    </activation>
    ...
  </profile>
</profiles>

Expected behavior: This profile gets activated if file with a name '.profile-A' exists in a root folder of a project.

However, at this point one more interesting question arises: what would be the behavior in case of aggregated build?

OTHER TIPS

It sounds you need to use a Repository Manager (Archiva, Artifactory, Nexus alphabetical order) to have a single configuration in your settings.xml file. This will solve the issue of making your build files environment depend.

I prefer this way in my projects:

<profile>
  <id>dev</id>
  <activation>
    <property>
      <name>env</name>
      <value>dev</value>
    </property>
  </activation>
  ...
</profile>

Then you can activate it this way:

mvn your_goal -Denv=dev

Regards,

Boskop

you can simple add the activeByDefault tag to your maven profile:

<profiles>
    <profile>
    <id>your-profile</id>
        <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    </profile>
</profiles>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top