Maven: How to skip sub-modules if a profile is activated?

409 views Asked by At

I want Maven to skip building all sub-modules if the user neglects to specify a build profile. https://stackoverflow.com/a/8305931/14731 explains how to include a module if a profile is selected, but not how to exclude it.

I understand I can copy the <modules> to build into all non-default profiles but the list of modules is huge and I have over 9 different profiles, making this a maintenance nightmare.

Is there a way to exclude/skip sub-modules if a profile is activated? Alternatively, is there a way to store the module list into a property and re-use it from multiple profiles without having to repeat the entire list each time?

1

There are 1 answers

0
Stephen Connolly On BEST ANSWER

Question 1

Is there a way to exclude/skip sub-modules if a profile is activated?

Only way I can see is to only define modules in profiles for which they should be active, perhaps including a 'special' profile that is activeByDefault if you want them active by default...

But that suffers from the issue that if somebody does

mvn verify -P+profile

Then the active by default profiles will still be active (i.e. the modules will still be there)

Note: -Pprofile activates the profile named profile and deactivates all active by default profiles. -P-profile deactivates the (presumably) active by default profile named profile. -P+profile activates the profile names profile without affecting the active profiles.

Question 2

Alternatively, is there a way to store the module list into a property and re-use it from multiple profiles without having to repeat the entire list each time?

Not that I am aware of. Property substitution is, in general, not available while Maven is computing the build plan.