Maven一次性构建多个配置文件 [英] Maven Build multiple profiles in one go

查看:114
本文介绍了Maven一次性构建多个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的政策是仅构建1个可部署的jar.所有特定于环境的配置都保持独立,我们将它们一次构建在一起.因此,在当前的Ant流程下,我们为每个环境都有一个属性文件,对其进行循环,并为每个环境创建一组配置文件.

It is our policy to only build 1 deployable jar. all environment-specific configurations are kept separate, and we build them all together at once. so under our current Ant process, we have a properties file for each environment, loop over them, and create a set of config files for each environment.

在我当前的POM XML中,我只能构建一个在命令行中提供的配置文件.通过Maven可以实现吗?

In my current POM XML, I'm able to build only one profile supplied at the Command-line. Is it possible to achieve through Maven?

这是POM.xml的一些相关部分

Here are some of the relevant part of 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)

Thanks, Prabhjot

推荐答案

Maven不像蚂蚁.使用ant,您基本上可以在需要时做自己想做的事情.使用Maven可以清楚地记录在案的构建生命周期,它的目标是构建一个组件(并可能将其他工件附加到构建中).

Maven is not like ant. With ant, you can basically do what you want when you want to do it. With maven, there is a clear and documented build life cycle, and it's targeted at building one component (and possibly attaching other artifacts to the build).

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

What you plan to do is however to build one component multiple times, but with different parameters. This does not fit into the maven lifecycle. So what you will need to do is to cause some external process to do the iteration and call maven repeatedly with different parameters.

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

The classic way to accomplish this would be to use a shell script, but you can also use the Maven Invoker to launch a separate process from a Java or Maven context.

这篇关于Maven一次性构建多个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆