从命令行停用Maven配置文件 [英] De-activate a maven profile from command line
问题描述
我的Maven设置文件〜/.m2/settings.xml 中有一个默认激活的配置文件.
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
推荐答案
是的,确实,您有正确的方法. 从 maven个人资料用户指南
Yes indeed, you have the right way. From maven profiles user guide
停用个人资料
从Maven 2.0.10开始,可以使用命令行通过在标识符前面加上字符'!'来停用一个或多个概要文件.或-",如下所示:
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
这可用于停用标记为activeByDefault的配置文件,或通过其他方式通过其激活配置激活的配置文件.
This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config.
@Calfater在评论中指出,感叹号需要在大多数shell(bash,zsh以及Linux和MacOS上的其他shell)中转义,尽管不是在Windows命令行上.
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
或
mvn groupId:artifactId:goal -P '!profile-1'
这篇关于从命令行停用Maven配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!