Maven配置本地仓库和阿里中央仓库

star2017 1年前 ⋅ 1407 阅读

设置 Maven 远程仓库为阿里云提供的仓库,以便国内快速稳定下载依赖。阿里云 Maven 仓库代理了很多公共的 maven 仓库。

阿里云 Maven 仓库阿里云 Maven 公共代理库新版maven.aliyun.com答疑

中央仓库

Maven 默认使用 Apache 仓库,地址:https://repo.maven.apache.org/maven2 ,即当 maven 的配置文件 settings.xml 里的 <mirrors>标签内容为空时使用。

远程中央仓库有:

  1. Apache 仓库:https://repo.maven.apache.org/maven2
  2. Maven 中央仓库:http://central.maven.org/maven2/
  3. Maven repo1 仓库:https://repo1.maven.org/maven2/
  4. Spring 仓库:http://repo.spring.io/libs-milestone/

阿里仓库

设置仓库

阿里 Maven 仓库进行了改版,但与旧版兼容,旧的仓库地址仍可继续使用。

  1. 编辑 maven 配置文件 settings.xml,找到 localRepository标签,设置本地仓库地址。

    <localRepository>D:\Maven\repository</localRepository>
    
  2. 添加仓库镜像源

    打开 maven 的配置文件(一般在 maven 安装目录的 conf/settings.xml),在<mirrors></mirrors>标签中添加 mirror 子节点:

    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>  
      <name>public</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>            
    </mirror>
    

旧仓库地址

<mirror>
  <id>aliyunmaven</id>
  <mirrorOf>*</mirrorOf>  
  <name>public</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>            
</mirror>

新仓库地址

<mirror>
    <id>ali central</id>
    <mirrorOf>*</mirrorOf>  
    <name>central</name>
    <url>https://maven.aliyun.com/repository/central</url>            
</mirror>
<mirror>
    <id>ali public</id>
    <mirrorOf>*</mirrorOf>  
    <name>public</name>
    <url>https://maven.aliyun.com/repository/public</url>            
</mirror>

依赖包问题

commons-logging-1.2.jar

commons-logging-1.2.jar 包 SHA1 校验不通过问题

新装了一台 Ubuntu 服务器,安装 Maven 后,配置了 阿里中央仓库,Maven 打包项目,全新下载所有依赖。

使用 central 仓库,地址:https://maven.aliyun.com/repository/central ,在 Ubuntu 下执行 mvn 命令打包,安装依赖时报 commons-logging-1.2 包的 SHA1 校验不通过,mvn 命令从该仓库下载的包与 Maven 中央仓库不一致。在使用 spring-boot-maven-plugin 打成镜像时直接报异常:

[WARNING] Checksum validation failed, expected 4bfc12adfe4842bf07b657f0369c4cb522955686 but is 90a941b7b28fba6827b7810b8098b4abf54c196a from central repo for https://maven.aliyun.com/repository/central/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
[WARNING] Could not validate integrity of download from https://maven.aliyun.com/repository/central/commons-logging/commons-logging/1.2/commons-logging-1.2.jar: Checksum validation failed, expected 4bfc12adfe4842bf07b657f0369c4cb522955686 but is 90a941b7b28fba6827b7810b8098b4abf54c196a
[WARNING] Checksum validation failed, expected 4bfc12adfe4842bf07b657f0369c4cb522955686 but is 90a941b7b28fba6827b7810b8098b4abf54c196a from central repo for https://maven.aliyun.com/repository/central/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
Downloaded from central repo: https://maven.aliyun.com/repository/central/commons-logging/commons-logging/1.2/commons-logging-1.2.jar (2.6 MB at 72 kB/s)

Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default) on project wd-daoliu-admin: Execution default of goal com.spotify:docker-maven-plugin:0.4.13:build failed: A required class was missing while executing com.spotify:docker-maven-plugin:0.4.13:build: org/apache/commons/logging/LogFactory

阿里 central 仓库下载的 commons-logging-1.2.jar 是 2502 KB,而 Maven 中央仓库该包是 61 KB,但两个目录里的 SHA1 文件里的值是一致的 4bfc12adfe4842bf07b657f0369c4cb522955686

经对比测试,初步确定是 阿里 central 仓库该包的问题,更换 apache 和 maven 中央仓库都正常。

注意:是执行 mvn 命令下载的包出现了该问题。从页面找到该包下载,又是正确的(大小、SHA1一致)

更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: