How do I invoke two different profiles in one maven command?
Asked Answered
E

4

83

I have two profiles for different environments in pom.xml, I have to run mvn -PTest1 install and mvn -PTest2 install command to get these profiles in use. Can we integrate two separate maven commands in a single one (like mvn clean install)?

Here is my Pom entry

<profiles>
  <profile>
  <id>Test1</id>
  <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.5</jdk>
    <os>
       <name>Windows XP</name>
       <family>Windows</family>
       <arch>x86</arch>
       <version>5.1.2600</version>
    </os>
    <property>
       <name>sparrow-type</name>
       <value>African</value>
    </property>
  </activation>
  <dependencies>
    <dependency>
      <groupId>
      com.endeca
      </groupId>
      <artifactId>
      endeca_navigation_Test1
      </artifactId>
     <version>
     6.1
     </version>
     <!--<version>stable</version> -->
    <scope>
    compile
    </scope>
  </dependency>
  </profile>

  <profile>
    <id>Test2</id>
    <activation>
      <activeByDefault>false</activeByDefault>
      <jdk>1.5</jdk>
      <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
      </os>
      <property>
        <name>sparrow-type</name>
        <value>African</value>
      </property>
    </activation>
    <dependencies>
      <dependency>
        <groupId>
        com.endeca
        </groupId>
        <artifactId>
        endeca_navigation_Test2
        </artifactId>
        <version>
        6.1
        </version>
        <!--<version>stable</version> -->
        <scope>
        compile
        </scope>
      </dependency>
    </dependencies>
  </profile>
</profiles>

It will helpfull to manage hudson job using single command

Erena answered 28/5, 2013 at 12:48 Comment(2)
So you want to combine commands mvn -PTest1 install and mvn -PTest2 install? – Gormless
I need to integrate these two commands mvn -PTest1 install and mvn -PTest2 install with my Hudson job command mvn install. The mvn install is handling with Hudson job for our project. – Erena
G
113

Based on the documentation and discussion here, try separating profile names with a comma:

mvn install -P Test1,Test2
Gormless answered 28/5, 2013 at 13:0 Comment(1)
the link to discussion is dead πŸ’€πŸ’€πŸ’€ – Ignazio
I
34

Mifeet's answer is correct, but in Windows PowerShell you should quote parameters, otherwise you'll get "unknown lifecycle phase" error.

mvn install -P 'Test1,Test2'
Ignazio answered 13/12, 2017 at 1:23 Comment(1)
For me it is " " , I am using cmd – Fadil
L
27

For me Mifeet's answer isn't working. I get "unknown lifecycle phase Test2". For me this is working:

mvn install -PTest1 -PTest2
Libeler answered 13/3, 2017 at 14:35 Comment(1)
Are you using PowerShell? See naXa's answer. – Justinajustine
H
8

Based on the maven help command

 -P,--activate-profiles <arg>   Comma-delimited list of profiles to activate

So you can run mvn package -Pp1,p2 to run profile id with p1 and p2

Harmonic answered 15/6, 2020 at 6:9 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.