Java 从命令行取消激活 Maven 配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25201430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
De-activate a maven profile from command line
提问by Calfater
I have a profile activated by defaultin my maven setting file ~/.m2/settings.xml.
我的Maven 设置文件~/.m2/settings.xml 中有一个默认激活的配置文件。
Is it possible to deactivate it from the command line by doing something like this:
是否可以通过执行以下操作从命令行停用它:
mvn -P!profileActivatedByDefault
采纳答案by GPI
Yes indeed, you have the right way. From maven profiles user guide
是的,你有正确的方法。来自Maven 配置文件用户指南
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.
停用配置文件
从 Maven 2.0.10 开始,可以使用命令行停用一个或多个配置文件,方法是在其标识符前加上字符“!” 或 '-' 如下所示:
mvn groupId:artifactId:goal -P !profile-1,!profile-2
这可用于停用标记为 activeByDefault 的配置文件或否则将通过其激活配置激活的配置文件。
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.
正如@Calfater 在评论中所指出的,感叹号需要在大多数 shell(bash、zsh 以及 Linux 和 MacOS 上的其他 shell)中转义,但不在 windows 命令行中。
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'
回答by SparkOn
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:
从 Maven 2.0.10 开始,可以使用命令行停用一个或多个配置文件,方法是在其标识符前加上字符“!” 或 '-' 如下所示:
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
这可用于停用标记为 activeByDefault 的配置文件或否则将通过其激活配置激活的配置文件。 参考 Maven 文档
Because !
Exclamation mark is a special character for most of the command line tools, you might need to escape it refer here.
由于!
感叹号是大多数命令行工具的特殊字符,因此您可能需要对其进行转义,请参阅此处。
回答by Shaun Morris
On a Mac, I got the following error attempting to use '!'
在 Mac 上,我在尝试使用“!”时遇到以下错误
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