Maven Build multiple profiles in one go

怎甘沉沦 提交于 2019-11-27 04:49:19

问题


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.

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?

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>

.....

Thanks, Prabhjot


回答1:


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).

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.

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.



来源:https://stackoverflow.com/questions/4932944/maven-build-multiple-profiles-in-one-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!