Search
Calendar
July 2025
S M T W T F S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031  
Archives

PostHeaderIcon Multi-profiles with Maven 2

Case: you work on two different projects, which use different repositories. How to search, find and download needed jars owing to the project?

Maven2 allows you to define different profiles.
For that, edit your Maven2 config file, available at $HOME/.m2/settings.xml.

Define your first profile:

<profile>
    <properties>
       <maven.user>jlalou</maven.user>
       <myProject.version>12.3</myProject.version>
    </properties>
    <repositories><repository>
  <id>FirstProjectID</id>
  <name>My First Project</name>
  <url>http://blabla.bla.bla</url>
  <releases>
    <enabled>true</enabled>
    <checksumPolicy>warn</checksumPolicy>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  <checksumPolicy>fail</checksumPolicy>
  </snapshots>
</repository></repositories>
</profile>

Define your first profile:

<profile>
    <properties>
      <maven.user>genericUser</maven.user>
      <myProject.version>45.6</myProject.version>
    </properties>
    <repositories><repository>
  <id>SecondProjectID</id>
  <name>My Personnal Project</name>
  <url>http://foo.foo.foo</url>
  <releases>
    <enabled>true</enabled>
    <checksumPolicy>warn</checksumPolicy>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  <checksumPolicy>fail</checksumPolicy>
  </snapshots>
</repository></repositories>
</profile>

At the end of the file, add following tags:

    
<activeProfiles>
    <activeProfile>FirstProjectID</activeProfile>
    <activeProfile>SecondProjectID</activeProfile>
 </activeProfiles>

Now, on compiling, use the option -P to hint which project/profile you want to use:
maven clean install -PFirstProjectID

Leave a Reply