如何在Maven3中指定活动配置文件

10
我们的应用由多个活动配置文件(例如A1、A2、A3、A5...)组成,这些配置文件在profiles.xml文件中分别定义。Maven 3希望将所有配置文件信息存储在pom.xml文件本身中。
我应该如何在pom.xml文件中指定活动配置文件列表,以避免在命令行中指定它们(例如mvn -PA1、A2、A3、A5)?
2个回答

10

这个代码是否可以解决问题:

<profiles>
  <profile>
    <id>profile-1</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    ...
  </profile>
</profiles>

翻译自这里.


我不能为多个配置文件指定这个,我认为这个建议不起作用。 - user339108

5

除了@javamonkey79的回答之外,您还可以使用settings.xml。其中包含配置文件和激活的部分。请参考以下示例:

 <profiles>
  <profile>
   <id>hudson-simulate</id>
   <properties>
    <gituser>username</gituser>
    <gitpassword>secret</gitpassword>
   </properties>
  </profile>
  <profile>
   <id>other-profile</id>
   <properties>
    <proerty1>username</property1>
   </properties>
  </profile>
 </profiles>

 <activeProfiles>
  <activeProfile>hudson-simulate</activeProfile>
  <activeProfile>other-profile</activeProfile>
 </activeProfiles>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接