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

use*_*108 10 profile maven-3 maven

我们的应用程序包含各种活动配置文件(例如A1,A2,A3,A5 ...),它们在profiles.xml文件中单独定义.Maven 3期望将所有配置文件信息存储为pom.xml文件本身的一部分.

我应该如何在pom.xml文件中指定活动配置文件列表,以便我可以避免在命令行中指定它们(例如mvn -PA1,A2,A3,A5)

jav*_*y79 10

应该这样做:

<profiles>
  <profile>
    <id>profile-1</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    ...
  </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

这里开始.


Fun*_*242 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>
Run Code Online (Sandbox Code Playgroud)