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

梦想与她 提交于 2019-12-18 12:43:29

问题


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


回答1:


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

mvn install -P Test1,Test2



回答2:


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

mvn install -PTest1 -PTest2



回答3:


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'


来源:https://stackoverflow.com/questions/16792499/how-do-i-invoke-two-different-profiles-in-one-maven-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!