De-activate a maven profile from command line

不羁的心 提交于 2019-12-20 09:08:30

问题


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

回答1:


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'



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/25201430/de-activate-a-maven-profile-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!