繁体   English   中英

"如何在一个 Maven 命令中调用两个不同的配置文件?"

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

我在pom.xml<\/code>中有两个用于不同环境的配置文件,我必须运行mvn -PTest1 install<\/code>和mvn -PTest2 install<\/code>命令才能使用这些配置文件。 我们可以将两个单独的 maven 命令集成到一个命令中(例如mvn clean install<\/code> )吗?

这是我的 Pom 条目

<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>

对我来说,Mifeet 的回答不起作用。 我得到“未知的生命周期阶段 Test2”。 对我来说,这是有效的:

mvn install -PTest1 -PTest2

基于 maven help 命令

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

这不是一个答案,而是讨论,我尝试@naXa 的命令的输出看起来如何,我认为它只显示此消息

[WARNING] The requested profile "'test" could not be activated because it does not exist.
[WARNING] The requested profile "normal'" could not be activated because it does not exist.

我运行的命令

mvn test -P 'test,normal'

所以,问题是我如何识别已经运行两个配置文件?

当我用双引号运行突击队时不会显示警告,但我认为只执行普通配置文件,因为它显示

[INFO] Executing tasks
 [echo] Using env.properties
[INFO] Executed tasks

当我使用@dermoritz、@sendon1982 和@Mifeet 提出的版本时,也会发生类似的情况

mvn test -Ptest -Pnormal
mvn test -Ptest,normal

所以我不确定应该怎么看。 谢谢你的帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM