前言:有一个要求就是说不能使用明文密码,需要对 settings.xml 文件中的password密码进行加密
maven版本: 3.6.3
原始配置是没有对密码进行加密的
<server>
<id>gleam-repo</id>
<username>admin</username>
<password>admin123</password>
</server>
这是接下来需要用到的两个命令
mvn --encrypt-master-password "加盐值"
mvn --encrypt-password "需要加密的密码"
输入 mvn --encrypt-master-password 回车然后输入给密码加盐的盐值

然后将上面获取到的加密盐值放到 当前登录用户名\.m2\settings-security.xml 的这个文件的 master 标签内,没有这个文件就新建,以下是这个文件的完整内容
<!--
maven安全配置文件(如果没有就手动创建), 内容如下
linux下路径: ~/.m2/settings-security.xml
window下路径: %USERPROFILE%\.m2\settings-security.xml
window下路径: 当前登录用户名\.m2\settings-security.xml
%USERPROFILE% 指当前登录windows的用户, 比如我当前登录的账号是admin
完整示例: C:\Users\admin\.m2
-->
<settingsSecurity>
<!-- master的值为 mvn encrypt-master-password 生成的密文-->
<master>{2yB41Sc3/uUHseN39zLQB+14crvBhxsQRaXWgOTjdy8=}</master>
</settingsSecurity>

输入 mvn --encrypt-password 回车然后输入要加密的仓库密码,比如我的就输入 admin123,然后回车得到的密码就是加密后的密码

替换 settings.xml 中的password即可
<server>
<id>gleam-repo</id>
<username>admin</username>
<password>{TVKDNf7AL24H6+DZZwlMsc7DCGp+98I0Fa/ZSYTQ4v8=}</password>
</server>
<?xml version="1.0" encoding="UTF-8"?>
<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>C:\environment\apache-maven-3.6.3\maven-repo</localRepository>
<!-- 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>
<!-- 配置仓库的用户名密码, 下面要使用这个id即可 -->
<server>
<id>gleam-repo</id>
<username>admin</username>
<password>{TVKDNf7AL24H6+DZZwlMsc7DCGp+98I0Fa/ZSYTQ4v8=}</password>
</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>
<!-- 使用server中的id, 这里不需要再配置用户的账号和密码了 -->
<id>gleam-repo</id>
<name>zz-repo</name>
<url>http://192.112.113.77:9921/nexus/content/groups/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
<!-- <mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>aliyun-maven</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror> -->
</mirrors>
<profiles>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>dev</id>
<repositories>
<repository>
<!-- 使用server中的id, 这里不需要再配置用户的账号和密码了 -->
<id>gleam-repo</id>
<url>http://192.112.113.77:9921/nexus/content/groups/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>gleam-repo</id>
<name>deployment</name>
<url>http://192.112.113.77:9921/nexus/content/groups/maven-public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!-- 需要激活的配置, 填profile中的id即可 -->
<activeProfile>aliyun</activeProfile>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>