2011-02-08 33 views
15

我们的政策是只构建一个可部署的jar。所有环境特定的配置都保持独立,我们一起构建它们。所以在我们当前的Ant过程中,我们为每个环境都有一个属性文件,循环它们,并为每个环境创建一组配置文件。Maven一次构建多个配置文件

在我目前的POM XML中,我只能在命令行中构建一个配置文件。是否有可能通过Maven实现?

这里有一些的pom.xml

<!-- Define profiles here and make DEV as default profile --> 
<profiles> 

    <!-- dev Profile --> 
    <profile> 
     <id>dev</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
    </profile> 

    <!-- qa Profile --> 
    <profile> 
     <id>qa</id> 
     <properties> 
      <env>qa</env> 
     </properties> 
    </profile> 

    <!-- prod Profile --> 
    <profile> 
     <id>prod</id> 
     <properties> 
      <env>prod</env> 
     </properties> 
    </profile> 

</profiles> 
... 


<plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>2.4.3</version> 

    <executions> 
     <execution> 

      <phase>validate</phase> 
      <goals> 
       <goal>copy-resources</goal> 
      </goals> 

      <configuration> 

       <filters> 
        <filter>env/${env}.properties</filter> 
       </filters> 

       <outputDirectory>${project.build.directory}/config/${env} 
       </outputDirectory> 
       <resources> 
        <resource> 

         <filtering>true</filtering> 

         <directory>${basedir}/src/main/config/default 
         </directory> 
         <includes> 
          <include>*.xml</include> 
          <include>*.properties</include> 
         </includes> 
        </resource> 

的相关部分的.....

感谢, Prabhjot

+0

这里描述的解决方法为: https://stackoverflow.com/questions/12320322/build-multiple-artifacts-with-different-classifiers-at-once – stokito 2015-06-30 11:32:09

回答

19

Maven是不喜欢蚂蚁。用蚂蚁,你可以基本上做你想做的事情。有了maven,有一个明确的文档build life cycle,它的目标是构建一个组件(并可能将其他工件附加到构建中)。

然而,您打算做的是多次构建一个组件,但使用不同的参数。这不适合Maven的生命周期。所以你需要做的是引起一些外部进程做迭代,并用不同的参数重复调用maven。

完成此操作的经典方法是使用shell脚本,但您也可以使用Maven Invoker从Java或Maven上下文启动单独的进程。

相关问题