Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

De-activate a maven profile from command line

I have a profile activated by default in my maven setting file ~/.m2/settings.xml.

Is it possible to deactivate it from the command line by doing something like this:

mvn -P!profileActivatedByDefault
like image 377
Calfater Avatar asked Aug 08 '14 10:08

Calfater


People also ask

What is profile in Maven?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.


3 Answers

Yes indeed, you have the right way. From maven profiles user guide

Deactivating a profile

Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' as shown below:

mvn groupId:artifactId:goal -P !profile-1,!profile-2

This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config.

As noted by @Calfater in the comments, the exclamation mark needs to be escaped in most shells (bash, zsh, and others on Linux and MacOS), though not on the windows command line.

The escape mechanisms are shell-dependant, but usually you can do :

mvn groupId:artifactId:goal -P \!profile-1

Or

mvn groupId:artifactId:goal -P '!profile-1'

Or, as Shaun Morris suggested below, use - instead of !, but without whitespace between -P and the profiles:

mvn groupId:artifactId:goal -P-profile-1,-profile2
like image 60
GPI Avatar answered Oct 25 '22 21:10

GPI


On a Mac, I got the following error attempting to use '!'

mvn groupId:artifactId:goal -P!profile-1
-bash: !profile: event not found

Doing the following works with the '-':

mvn groupId:artifactId:goal -P-profile1

Alternatively you can do:

mvn groupId:artifactId:goal -P\!profile1
like image 23
Shaun Morris Avatar answered Oct 25 '22 19:10

Shaun Morris


Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' as shown below:

mvn groupId:artifactId:goal -P !profile-1,!profile-2

This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config. Refer Maven Doc

Because ! Exclamation mark is a special character for most of the command line tools, you might need to escape it refer here.

like image 37
SparkOn Avatar answered Oct 25 '22 21:10

SparkOn