Maven一次构建多个配置文件

Pra*_*jot 17 maven-2 profiles maven

我们的政策是只构建1个可部署的jar.所有特定于环境的配置都是分开的,我们一起构建它们.所以在我们当前的Ant流程中,我们为每个环境都有一个属性文件,循环遍历它们,并为每个环境创建一组配置文件.

在我目前的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>
Run Code Online (Sandbox Code Playgroud)

.....

谢谢,Prabhjot

Sea*_*oyd 22

Maven不像蚂蚁.使用ant,您基本上可以根据需要执行所需操作.使用maven,有一个清晰且有文档记录的构建生命周期,它的目标是构建一个组件(并可能将其他工件附加到构建中).

但是,您计划要多次构建一个组件,但参数不同.这不适合maven生命周期.所以你需要做的是让一些外部进程进行迭代并使用不同的参数重复调用maven.

实现此目的的经典方法是使用shell脚本,但您也可以使用Maven Invoker从Java或Maven上下文启动单独的进程.