简体   繁体   English

在pom.xml和settings.xml中覆盖Maven属性的顺序是什么?

[英]What is the order of overwrite Maven properties in pom.xml and settings.xml?

today I observed that the maven proprties defined in settings.xml overwrite the one in pom.xml . 今天我观察到,在规定的行家根据企业的性质settings.xml覆盖一个在pom.xml

Because it is only a observation, I am not sure if this is totally correct. 因为这只是观察,我不确定这是否完全正确。 So I am looked for the reference or some article but I find no concrete statement about the behaviour of overwriting properties defined with the same name in settings.xml and pom.xml . 所以我查找了参考文章或一些文章,但我没有找到关于覆盖在settings.xmlpom.xml使用相同名称定义的属性的行为的具体说明。

Maybe someone can provide a link to the reference part (that I may overlooked) or the a reliable article/blog? 也许有人可以提供参考部分的链接(我可能会忽略)或可靠的文章/博客?

Based on the documentation in my opinion it is clear which one has precedence over the other (excerpt of the docs): 基于我认为的文档 ,很清楚哪一个优先于另一个(文档的摘录):

If a profile is active from settings, its values will override any equivalently ID'd profiles in a POM or profiles.xml file. 如果配置文件在设置中处于活动状态,则其值将覆盖POM或profiles.xml文件中任何等效的ID'd配置文件。

The profiles.xml does not exist anymore in Maven 3 only in Maven 2.2.1 it is supported but shouldn't be used. 仅在Maven 2.2.1中,profiles.xml不再存在于Maven 3中,它受支持但不应使用。

I think properties with equal names are overridden in next sequence (from highest to lowest context): 我认为具有相同名称的属性在下一个序列中被覆盖(从最高到最低的上下文):

  • Global 全球
  • Profile descriptor 档案描述符
  • Per project 每个项目
  • Per user 每个用户

http://maven.apache.org/guides/introduction/introduction-to-profiles.html http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Hence, pom.xml properties (per project) are overridden by settings.xml (per user) properties with equal names. 因此, pom.xml属性(每个项目)被具有相同名称的settings.xml (每个用户)属性覆盖。

Just tested it on my maven 3.3.9. 刚刚在我的maven 3.3.9上测试过它。

First of all, properties are always defined in profiles, if we are talking about settings.xml. 首先,如果我们讨论的是settings.xml,那么属性总是在配置文件中定义。 Properties from global settings XML have the highest priority and will override both user settings.xml and a specific pom.xml , UNLESS there is a name collision between profiles. 全局设置中的属性XML具有最高优先级,并且将覆盖用户settings.xml和特定的pom.xml除非配置文件之间存在名称冲突。

If it's the case, that is there is a profile with the same id in global, user settings, as well as pom.xml, user/local settings.xml is the boss. 如果是这种情况,那就是在全局,用户设置以及pom.xml中都有一个具有相同id配置文件 ,user / local settings.xml就是老板。 Even if a property in pom.xml doesn't sit inside a profile, user/local settings.xml property from an active profile with the same name will beat it. 即使pom.xml中的属性不在配置文件中,来自具有相同名称的活动配置文件的user / local settings.xml属性也会超过它。 Incidentally, global settings.xml will also beat pom.xml property without a profile. 顺便说一下,全局settings.xml也会在没有配置文件的情况下击败pom.xml属性。

As a side note: For <repositories> and <mirrors> the logic is slightly different: 作为旁注:对于<repositories><mirrors> ,逻辑略有不同:

  • User/local settings have higher priority than global for <mirrors> . 对于<mirrors>用户/本地设置的优先级高于全局。
  • However, for <repositories> : pom - highest, then - local, then - global. 但是,对于<repositories> :pom - 最高,然后 - 本地,然后 - 全局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM