Maven Profile配置activeByDefault和activeProfiles的区别

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.
也就是说配置了标签的profile只会在没有其他激活的profile的情况下被激活
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.
里配置的profile会无视其激活条件默认激活,如果指定的profile id不存在则忽略
总结 【Maven Profile配置activeByDefault和activeProfiles的区别】当我们需要配置一个所有环境都激活的profile,用配置,而需要配置一个其他profile都没有激活的兜底profile时,用配置
例如:
  • 我们要在settings.xml文件里配置使用阿里云的仓库作为默认仓库,那这个仓库对应的profile就可以用激活
  • 项目的pom.xml通常会配置多个环境,线上prod和线下dev,线下环境的profile就可以用激活,这样编译就可以不用指定-P dev参数而默认就用dev环境

    推荐阅读