maven仓库配置

更新时间 🔔🕙 2023年9月21日

nexus私有化部署仓库https配置

一般我们都会将nexus服务配置在某个nginx的后面,这个时候,如果nginx上配置了https,我们就可通过https访问nexus。
但是,这个时候在nexus里面看到的repo的URL,仍然是http的。

这个时候,就需要在nginx上进行如下的配置,设置URL为https:

    location / {
      # Use IPv4 upstream address instead of DNS name to avoid attempts by nginx to use IPv6 DNS lookup
      proxy_pass http://127.0.0.1:8081/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto "https";
    }

参考网址:Run Behind a Reverse Proxy (sonatype.com)

部分maven仓库的国内源

参考网址:Maven | 腾讯云 (tencentcloud.com)
腾讯软件源 (tencent.com)

// 腾讯云 maven 镜像聚合了:central、jcenter、google、gradle-plugin
maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' }

阿里云也有很多maven仓库源,但是更新的有点问题,可以作为备用

# 在这里有很多国内源
https://developer.aliyun.com/mvn/view

gradle.zip的国内源

参考网址:腾讯软件源 (tencent.com)
Is gradle stored in a nexus repo? – Stack Overflow

由于有时候直接从gralde服务器上下载zip文件比较慢,最好的方式是我们自己缓存起来。
我们可以创建一个raw (proxy) 的repository,代理https://services.gradle.org/distributions。这样可以代理所有的请求。

# 我们原本要访问的地址
curl https://services.gradle.org/distributions/gradle-6.9.1-wrapper.jar.sha256
# 经过nexus代理之后,我们访问的地址
curl https://nexus.xxxx.com/repository/gradle-distributions/gradle-6.9.1-wrapper.jar.sha256

gradle-wrapper.properties文件中,我们修改gradle的下载地址就行。

distributionUrl=https://nexus.xxxx.com/repository/gradle-distributions/gradle-6.9.1-bin.zip
转载请备注引用地址:编程记忆 » maven仓库配置