【问题标题】:Maven Build multiple profiles in one goMaven 一次构建多个配置文件
【发布时间】:2011-06-23 09:47:02
【问题描述】:

我们的政策是只构建 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>

.....

谢谢, 普拉布乔特

【问题讨论】:

标签: maven-2 maven profiles


【解决方案1】:

Maven 不像蚂蚁。有了ant,你基本上可以随心所欲地做你想做的事。对于 maven,有一个清晰且有文档记录的 build life cycle,它的目标是构建一个组件(并可能将其他工件附加到构建中)。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多