Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip a submodule during a Maven build

We have a need to be able to skip a submodule in certain environments.

The module in question contains integration tests and takes half an hour to run. So we want to include it when building on the CI server, but when developers build locally (and tests get run), we want to skip that module.

Is there a way to do this with a profile setting? I've done some googling and looked at the other questions/answers here and haven't found a good solution.

I suppose one option is to remove that submodule from the parent pom.xml entirely, and just add another project on our CI server to just build that module.

Suggestions?

like image 603
denishaskin Avatar asked Nov 29 '11 00:11

denishaskin


People also ask

What does clean install mean in Maven?

mvn clean install tells Maven to do the clean phase in each module before running the install phase for each module. What this does is clear any compiled files you have, making sure that you're really compiling each module from scratch.

What is Maven submodule?

Submodules Submodules, or subprojects, are regular Maven projects that inherit from the parent POM. As we already know, inheritance lets us share the configuration and dependencies with submodules.


2 Answers

Maven version 3.2.1 added this feature, you can use the -pl switch (shortcut for --projects list) with ! or - (source) to exclude certain submodules.

mvn -pl '!submodule-to-exclude' install mvn -pl -submodule-to-exclude install 

Be careful in bash the character ! is a special character, so you either have to single quote it (like I did) or escape it with the backslash character.

The syntax to exclude multiple module is the same as the inclusion

mvn -pl '!submodule1,!submodule2' install mvn -pl -submodule1,-submodule2 install 

EDIT Windows does not seem to like the single quotes, but it is necessary in bash ; in Windows, use double quotes (thanks @awilkinson)

mvn -pl "!submodule1,!submodule2" install 
like image 131
Alexandre DuBreuil Avatar answered Sep 27 '22 15:09

Alexandre DuBreuil


Sure, this can be done using profiles. You can do something like the following in your parent pom.xml.

  ...    <modules>       <module>module1</module>       <module>module2</module>         ...   </modules>   ...   <profiles>      <profile>        <id>ci</id>           <modules>             <module>module1</module>             <module>module2</module>             ...             <module>module-integration-test</module>           </modules>        </profile>   </profiles>  ... 

In your CI, you would run maven with the ci profile, i.e. mvn -P ci clean install

like image 44
Raghuram Avatar answered Sep 27 '22 17:09

Raghuram