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不存在則忽略
總結(jié)
當我們需要配置一個所有環(huán)境都激活的profile钦睡,用<activeProfiles>
配置荞怒,而需要配置一個其他profile都沒有激活的兜底profile時洒琢,用<activeByDefault>
配置
例如:
- 我們要在settings.xml文件里配置使用阿里云的倉庫作為默認倉庫衰抑,那這個倉庫對應(yīng)的profile就可以用
<activeProfiles>
激活 - 項目的pom.xml通常會配置多個環(huán)境呛踊,線上prod和線下dev谭网,線下環(huán)境的profile就可以用
<activeByDefault>
激活逻族,這樣編譯就可以不用指定-P dev
參數(shù)而默認就用dev環(huán)境