How to exclude a module from a Maven reactor assembly?

We have a Maven 2 project with a lot of modules. Example:

<modules> <module>common</module> <module>foo</module> <module>data</module> <module>bar</module> ... more ... </module> 

Let's say the “data” module takes a lot of time to build, and we want to exclude it when the project is built by the CI server. We currently use two pom.xml files for this. It has all the modules, and in the other, all the modules except those that can be excluded for CI. But this is quite annoying because sometimes we forget to put a new module in both files.

Is there a solution that does not need two separate module lists?

+68
maven maven-2
Apr 04 2018-11-11T00:
source share
6 answers

The easiest way is to use profiles as follows:

 <project> ... <modules> <module>common</module> <module>foo</module> <module>bar</module> <modules> ... <profiles> <profile> <id>expensive-modules-to-build</id> <modules> <module>data</module> </modules> </profile> </profiles> </project> 

Then you can check how profiles are activated.

+58
Apr 04 '11 at 18:38
source share

With Maven 3.2.1, you can now use -pl !<module_name>,!<module_name> to exclude specific modules from the reactor assembly.

See this feature request: https://jira.codehaus.org/browse/MNG-5230

+79
Apr 01 '14 at 10:50
source share

Build projects can also be specified on the mvn command line. This would eliminate the need for a separate pom, but instead, you would have to change the CI configuration every time a new module appeared.

 -pl,--projects <arg> Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path. 

Perhaps a combination of this flag and --also-make-dependents or --also-make will again reduce this maintenance burden.

 -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 
+36
Apr 04 2018-11-11T00:
source share

I assume that you want the default assembly to always create everything, regardless of speed, so that new developers can get started quickly without understanding a lot about POM. You can use these profiles:

 <modules> <module>common</module> <module>foo</module> <module>bar</module> </modules> ... <profiles> <profile> <id>expensive-modules-to-build</id> <activation> <activeByDefault>true</activeByDefault> </activation> <modules> <module>data</module> </modules> </profile> </profiles> </project> 

The problem is that if the developer specifies a different profile on the command line, then expensive-modules-to-build does not turn on (unless the developer also specifies it). This makes it difficult to remember which profiles to enable.

Here is the hacker approach. Both profiles are always included, as the pom.xml file always exists. Thus, to exclude expensive modules, you can use -P!full-build on the command line.

 <profiles> <profile> <id>full-build</id> <activation> <file> <exists>pom.xml</exists> </file> </activation> <modules> <module>data</module> </modules> </profile> <profile> <id>short-build</id> <activation> <file> <exists>pom.xml</exists> </file> </activation> <modules> <module>common</module> <module>foo</module> <module>bar</module> </modules> </profile> </profiles> 
+19
Jul 11 2018-12-12T00:
source share

Another idea: reactor modules can be nested, so you can combine your fast and slow modules into separate pores, and then add another aggregator containing these two modules. Your CI server can then only refer to a pom containing fast building modules.

 <artifactId>fast</artifactId> <modules> <module>fast-a</module> <module>fast-b</module> <module>fast-c</module> </module> <artifactId>all</artifactId> <modules> <module>fast</module> <module>slow</module> </module> 
+6
Apr 04 2018-11-11T00:
source share

You can use maven profiles . In our build environment, we created a quick profile that disables many plugins and performs testing.

This is done

  <profile> <id>quick</id> <properties> <skipTests>true</skipTests> <!-- others... --> </properties> <build> <plugins> <!-- configuration... --> </plugins> </build> </profile> 

And then we call maven as follows

 mvn groupId:artifactId:goal -P quick 

Perhaps you can disable compilation and other standard plugins in your module folder to speed it up.

+1
Apr 04 2018-11-11T00:
source share



All Articles