maven - [02] settings.xml配置
maven处理配置的优先级顺序
(1)全局settings.xml(优先级★☆☆☆☆)
位于Maven安装目录的conf/settings.xml,提供系统级的默认配置,比如本地仓库位置、远程仓库列表等。这些设置对所有用户和项目都有效,但优先级最低。
(2)用户级别的settings.xml(优先级★★☆☆☆)
位于用户主目录下的
.m2/settings.xml,覆盖全局的settings.xml设置。这里的配置仅对当前用户生效,优先级高于全局settings.xml(3)父项目POM(优先级★★★☆☆)
父项目POM定义了所有子项目的共享配置,如依赖管理(dependencyManagement)、插件管理(pluginManagement)、构建配置等。父POM的设置为所有继承它的子项目提供了基础配置,但是子项目可以直接覆盖这些配置。
(4)子项目POM(优先级★★★★☆)
子项目的POM文件具有最高优先级,它可以覆盖来自父POM的所有配置,包括直接声明依赖、构建属性、插件配置等。子项目的直接配置将优先于任何上级配置。
(5)profiles和profile-specifix配置(优先级★★★★★)
不论是在settings.xml还是POM.xml中,激活的profiles可以进一步调整配置。如果一个profile在多个层级被定义(比如既有用户级settings.xml中的又有项目POM中的),那么激活的profile中定义的设置将根据定义的顺序(局部优先于全局)来覆盖之前的配置。
(6)其他配置文件(如profiles.xml等)(优先级★★★★★)
虽然不常见,但在特定场景下,Maven也允许使用或自定义其他配置文件,比如通过
profiles.xml来管理一组可激活的profiles。这些额外的配置同样遵循局部(项目或用户)优先于全局的原则。总结来说,Maven的配置优先级遵循“局部覆盖全局”和“子项目覆盖父项目”的原则,确保了灵活性和可维护性。开发者可以在更具体的层面(如子项目POM或激活的profiles)上进行精确控制,而不影响到更广泛的配置环境。
一、本地仓库(Local Repository)
指定Maven下载所有依赖包的位置。默认情况下,Maven会在用户目录下的.m2.reposiriey目录存储这些依赖
<localRepository>D:\Environment\mvnrepo</localRepository>
二、镜像(Mirrors)
配置国内maven仓库(阿里云、华为、网易...)的镜像地址,用于替换默认的中央仓库或其他远程仓库,提高依赖下载速度或解决访问受限问题。
<!-- 阿里云maven仓库仓库 -->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/spring</url>
<mirrorOf>spring</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/releases</url>
<mirrorOf>releases</mirrorOf>
</mirror>
<!-- 华为maven仓库 -->
<mirror>
<id>huaweicloud</id>
<name>mirrorfrommaven huaweicloud</name>
<url>https://repo.huaweicloud.com/repository/maven/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 163 -->
<mirror>
<id>nexus-163</id>
<mirrorOf>*</mirrorOf>
<name>网易 Nexus 163</name>
<url>http://mirrors.163.com/maven/repository/maven-public/</url>
</mirror>
三、代理(Proxies)
如果你的网络环境需要通过代理服务器访问外网,可以在这里配置HTTP、HTTPS或FTP代理
<proxies>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.example.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>proxypass</password>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
四、服务器(Servers)
配置访问私有仓库或部署时需要认证的服务器凭据。
<servers>
<server>
<id>server-id</id>
<username>your-username</username>
<password>your-password</password>
<!-- Optionally, for more security, you can use encrypted passwords -->
<!--<password>${env.MAVEN_PASSWORD}</password>-->
</server>
</servers>
五、全局属性(Properties)
可以在<properties>标签内定义一些全局变量,这些变量可以在POM文件中引用。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
我的settings.xml(D:\Environment\apache-maven-3.8.7\conf\settings.xml)
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\Environment\mvnrepo</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- <mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public</url>
<mirrorOf>public</mirrorOf>
</mirror> -->
<!-- 阿里云maven仓库仓库 -->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/spring</url>
<mirrorOf>spring</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/releases</url>
<mirrorOf>releases</mirrorOf>
</mirror>
<!-- 华为maven仓库 -->
<mirror>
<id>huaweicloud</id>
<name>mirrorfrommaven huaweicloud</name>
<url>https://repo.huaweicloud.com/repository/maven/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 163 -->
<mirror>
<id>nexus-163</id>
<mirrorOf>*</mirrorOf>
<name>网易 Nexus 163</name>
<url>http://mirrors.163.com/maven/repository/maven-public/</url>
</mirror>
<!-- junit镜像地址
<mirror>
<id>junit</id>
<name>junit Address/</name>
<url>http://jcenter.bintray.com/</url>
<mirrorOf>central</mirrorOf>
</mirror>
-->
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<!-- jdk1.8 -->
<profile>
<!-- profile的唯一标识 -->
<id>jdk-1.8</id>
<!-- 自动触发profile的条件逻辑 -->
<activation>
<!-- 当其值为true的时候表示如果没有其他的profile处于激活状态的时候,该profile将自动被激活。 -->
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<!-- 扩展属性列表 -->
<!-- 用于定义属性键值对的。当该profile是激活状态的时候,properties下面指定的属性都可以在pom.xml中使用。 -->
<!--如果Maven检测到某一个属性(其值可以在POM中通过${name}引用),
其拥有对应的name = 值,Profile就会被激活。如果值字段是空的,那么存在属性名称字段就会激活profile,
否则按区分大小写方式匹配属性值字段 -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
— 业精于勤荒于嬉,行成于思毁于随 —
maven - [02] settings.xml配置的更多相关文章
- Maven的settings.xml配置详解
子节点详细介绍转载:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension 全局配置 ...
- Maven 的 settings.xml 配置中的mirror节点
maven2的setting.xml大家都知道,里面有个mirrors节点,用来配置镜像URL. mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性 ...
- Maven settings.xml配置解读
本文对${maven.home}\conf\settings.xml的官方文档作个简单的解读,请确保自己的maven环境安装成功,具体安装流程详见Maven安装 第一步:看settings.xml的内 ...
- Maven——settings.xml配置
settings.xml配置 原文 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed ...
- Maven settings.xml配置(指定本地仓库、阿里云镜像设置)
转: 详解Maven settings.xml配置(指定本地仓库.阿里云镜像设置) 更新时间:2018年12月18日 11:14:45 作者:AmaniZ 我要评论 一.settings. ...
- Maven项目使用Nexus作为远程仓库的settings.xml配置
Maven项目使用Nexus作为远程仓库的settings.xml配置(转) 在自己电脑C:\Users\hanmm\.m2\下的setting.xml. 1.服务器配置 <server> ...
- [java][JEECG] Maven settings.xml JEECG项目初始化 RouYi settings.xml配置
好吧一下是经验之谈,原本这些坑不应该躺的,从头看手册完全可以避免这些. 懒得整理了,看懂了就看,看不懂自己琢磨JEECG的帮助文档去,不过嘛我喜欢用Intelij IDEA,他里面都是别的IDE,不喜 ...
- Maven学习存档(2)——settings.xml配置
二.settings.xml配置 2.1 原文 <?xml version="1.0" encoding="UTF-8"?> <!-- Lic ...
- Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):3、Maven独立插件安装与settings.xml配置
文章目录: Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):1.JIRA账号注册 Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):2.PGP ...
- IDEA设置maven修改settings.xml配置文件无法加载仓库
作为初学者配置maven一般网上搜索.然后你就看到各种配置文件片段,首先配置镜像,然后配置仓库.完事后再IDEA里面配置下maven的路径和配置文件路径. 这些文章属实坑爹,完全没讲一个重要的配置就是 ...
随机推荐
- LSTM学习三维轨迹的Python实现
一.引言 长短期记忆网络(LSTM)是一种强大的递归神经网络(RNN),广泛应用于时间序列预测.自然语言处理等任务.在处理具有时间序列特征的数据时,LSTM通过引入记忆单元和门控机制,能够更有效地捕捉 ...
- 对象存储 AVIF 图片压缩,即将公测!
2021年8月,腾讯云数据万象以内测方式推出了最前沿的 AVIF 图片压缩服务,可以在图片主观质量相同的情况下大幅降低码率,节省储存空间. 经过3个月时间的内测,我们收集到了很多热心用户的反馈,AVI ...
- 探索使用 ViewContainerRef 的 Angular DOM 操控技术
探索使用 ViewContainerRef 的 Angular DOM 操控技术 https://indepth.dev/posts/1052/exploring-angular-dom-manipu ...
- Kubernetes 可能是分布式架构的大结局了
前两年在爬虫里折腾的太久了,最近快马加鞭追赶分布式架构潮流. SpringCloud.Dubbo.ServiceComb 刷完,以为分布式架构就是这样了.这批架构可能也就 Java 栈的人会感觉它们特 ...
- Rocky Linux8升级9随记
发现Rocky Linux已经升级了9.0版本,看着自己用着的8.5版本,跃跃欲试,于是就索性升级了.两者的支持年限没有太大的差别,先说我的想法:升不升级无所谓. 并不是9.0有什么特别牛的特性,只是 ...
- docker-compose安装mongo
创建目录 [root@localhost tools]# mkdir -p /root/tools/mongo/{data,conf,init} 创建初始化用户脚本 [root@localhost m ...
- mysql:sql create database新建utf8mb4 数据库
create database sina default character set utf8mb4 collate utf8mb4_unicode_ci;或者是create database con ...
- 【转载】 一次生产环境的NOHTTPRESPONSEEXCEPTION异常的排查记录
https://www.freesion.com/article/41531004212/ 环境: jdk1.8+tomcat8+httpclient4.5.2 主要现象: 项目偶发出现org.apa ...
- Qt编写物联网管理平台39-报警联动
一.前言 本系统支持报警联动,就是某个探测器报警后,再去下发命令,通知下面的继电器警号,一般是通过串口发送,由于现场会利用现有的串口线路比如485总线,所以本系统需要做特殊处理,就是公用485通信总线 ...
- 主打一个“小巧灵动”:Vite + Svelte
作者:来自 vivo 互联网大前端团队- Wei Xing 在研发小型项目时,传统的 Vue.React 显得太"笨重".本文主要针对开发小型项目的场景,谈谈 Vite+Svel ...