• maven仓库密码加密,对settings.xml中的password进行加密


    前言:有一个要求就是说不能使用明文密码,需要对 settings.xml 文件中的password密码进行加密

    maven版本: 3.6.3

    原始配置是没有对密码进行加密的

    <server>
       <id>gleam-repo</id>
       <username>admin</username>
       <password>admin123</password>
     </server>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    加密

    这是接下来需要用到的两个命令

    mvn --encrypt-master-password "加盐值"
    mvn --encrypt-password "需要加密的密码"
    
    • 1
    • 2

    1 获取加密盐值

    输入 mvn --encrypt-master-password 回车然后输入给密码加盐的盐值

    在这里插入图片描述


    2 将加密盐值放到指定文件

    然后将上面获取到的加密盐值放到 当前登录用户名\.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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    在这里插入图片描述


    3 给密码进行加密

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

    在这里插入图片描述


    4 替换明文密码

    替换 settings.xml 中的password即可

    <server>
    	<id>gleam-repo</id>
    	<username>admin</username>
    	<password>{TVKDNf7AL24H6+DZZwlMsc7DCGp+98I0Fa/ZSYTQ4v8=}</password>
    </server>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    maven配置中央仓库的完整配置

    <?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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
  • 相关阅读:
    java-net-php-python-springboot教学评价系统计算机毕业设计程序
    读书笔记:软件工程(2) - 软件工程概述(2)
    【无线传感器】WSN 查找两个节点之间的最短路径并发送数据(Matlab代码实现)
    【算法刷题日记之本手篇】二进制插入与查找组成一个偶数最接近的两个素数
    DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
    智能优化算法 | Matlab实现ABC人工蜂群优化算法
    java毕业设计白天鹅造型网mybatis+源码+调试部署+系统+数据库+lw
    4. 串的【朴素模式匹配算法】、【KPM算法:求next数组、nextval数组】
    Android App冷启动耗时优化
    在Linux服务器中查找mysql的配置文件并修改其内容并保存,清空mysql8.0以上默认开启SSL的配置,防止odbc无法连接的问题
  • 原文地址:https://blog.csdn.net/weixin_44953227/article/details/125541955