美文网首页
Maven Profile配置activeByDefault和a

Maven Profile配置activeByDefault和a

作者: 花落红窗 | 来源:发表于2022-04-26 17:35 被阅读0次

activeByDefault

<activeByDefault>既能用在settings.xml也能用在pom.xml里

其作用maven官方文档是这么说的:

This profile will automatically be active for all builds unless another profile in the same POM is activated using one of the previously described methods.

也就是说配置了<activeByDefault>标签的profile只会在没有其他激活的profile的情况下被激活

activeProfiles

<activeProfiles>只能用在settings.xml文件

作用也看一下maven官方文档的说法:

The final piece of the settings.xml puzzle is the activeProfiles element. This contains a set of activeProfile elements, which each have a value of a profile id. Any profile id defined as an activeProfile will be active, regardless of any environment settings. If no matching profile is found nothing will happen. For example, if env-test is an activeProfile, a profile in a pom.xml (or profile.xml with a corresponding id will be active. If no such profile is found then execution will continue as normal.

<activeProfiles>里配置的profile会无视其激活条件默认激活,如果指定的profile id不存在则忽略

总结

当我们需要配置一个所有环境都激活的profile,用<activeProfiles>配置,而需要配置一个其他profile都没有激活的兜底profile时,用<activeByDefault>配置
例如:

  • 我们要在settings.xml文件里配置使用阿里云的仓库作为默认仓库,那这个仓库对应的profile就可以用<activeProfiles>激活
  • 项目的pom.xml通常会配置多个环境,线上prod和线下dev,线下环境的profile就可以用<activeByDefault>激活,这样编译就可以不用指定-P dev参数而默认就用dev环境

相关文章

网友评论

      本文标题:Maven Profile配置activeByDefault和a

      本文链接:https://www.haomeiwen.com/subject/hjkhyrtx.html