0
点赞
收藏
分享

微信扫一扫

maven setting.xml 解释

千白莫 2022-10-19 阅读 81


settings.xml文件位置

settings.xml文件一般存在于两个位置:

全局配置: ${maven.home}/conf/settings.xml

用户配置: ${user.home}/.m2/settings.xml

如果两个文件都存在,两个文件内容会合并,用户配置优先于全局配置。

因为默认的 安装目录自带的settings.xml里面什么都没有(全是注释),所以生效的就是自己目录下的那个settings.xml。


settings元素,就是定义maven的配置的。

settings下面的顶级元素,概览如下,一共9个。

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>


配置优先级

需要注意的是:局部配置优先于全局配置
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。


细节


一半的顶级元素都是简单的值


localRepository

作用:该值表示本地仓库的路径。

其默认值:~/.m2/repository。

<localRepository>${user.home}/.m2/repository</localRepository>

InteractiveMode

作用:表示maven是否需要和用户交互以获得输入。

如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。 这个都是true,不谈。

<interactiveMode>true</interactiveMode>

Offline

作用:表示maven是否需要在离线模式下运行。

一般不用设置,默认就是false,不离线。

<offline>false</offline>

PluginGroups

用到的插件列表,一般不需要设置


Servers 重要

作用:一般,仓库的下载和部署是在pom.xml文件中的repositoriesdistributionManagement元素中定义的。然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在pom.xml文件中配置,这些信息可以配置在settings.xml中。


例子

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
</server>
</servers>
...
</settings>

一般用这三个元素值就够了。




Mirrors 略过


Proxies 略过



官方文档:

​​​​https://maven.apache.org/settings.html​​


参考

​​https://www.cnblogs.com/jingmoxukong/p/6050172.html#activeprofiles​​




举报

相关推荐

0 条评论