Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 904
Craig S. Dickson Avatar asked Jul 23 '12 21:07

Craig S. Dickson


People also ask

Can two Maven modules depend on each other?

Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.


1 Answers

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
like image 95
Tomasz Krzyżak Avatar answered Oct 06 '22 01:10

Tomasz Krzyżak