How to activate a Maven Profile for a specific module in a mutli-module project

情到浓时终转凉″ 提交于 2019-12-09 03:34:34

问题


We have a multi-module Maven project consisting of a parent POM and 5 or more modules.

Each module can be deployed to a running server as part of the build if we activate our custom "auto-deploy" profile, which is defined explicitly in each module because how/what gets deployed is a little different for each of the modules.

When building from the parent POM though, if I activate the "auto-deploy" profile, Maven will end up deploying all modules, which is almost never what we need to do (based on our dev process etc). But we do want to build from the root as there can be changes across multiple modules and there are dependencies between some modules.

Is there a way, when building from the parent POM, to activate our custom "auto-deploy" Profile for just one of the Modules, but not all of them?

Thanks


回答1:


If each of your modules will have it's own "auto-deploy" profile, and profile activation will be triggered by variables passed to mvn command, you will be able to run single mvn command on parent module and decide which modules should be deployed simply by declaring activation variables

<profiles>
    <profile>
        <id>profileId</id>
        <activation>
            <property>
                <name>profileIdEnabled</name>
                <value>true</value>
            </property>
        </activation>
        <properties></properties>
    </profile>
</profiles>

and then

mvn -DprofileIdEnabled=true



回答2:


Check out Maven: The Complete Reference - Section 6.2. Using Advanced Reactor Options.

Starting with the Maven 2.1 release, there are new Maven command line options which allow you to manipulate the way that Maven will build multimodule projects. These new options are:

-rf, --resume-from

   Resume reactor from specified project

-pl, --projects

   Build specified reactor projects instead of all projects

-am, --also-make

   If project list is specified, also build projects required by the list

-amd, --also-make-dependents

   If project list is specified, also build projects that depend on projects on the list

To build only module-b from the root directory:

$ mvn --projects module-b install



来源:https://stackoverflow.com/questions/11620566/how-to-activate-a-maven-profile-for-a-specific-module-in-a-mutli-module-project

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