目的
加速构建;节省流量;集中托管;
安装
使用Nexus
下载地址
https://www.sonatype.com/download-nexus-repo-oss?submissionGuid=a664567c-2040-47d8-8f83-be951a48d54e
也就是:https://sonatype-download.global.ssl.fastly.net/nexus/3/latest-win64.zip
另外可以下载Maven
Maven:
http://maven.apache.org/download.cgi
http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
安装方法
解压后,CMD进入到bin文件夹内。
一种是安装为Windows服务(可以设置自动启动):
nexus.exe /install --> nexus.exe /start
或者直接运行:
nexus.exe /run
运行成功后访问:http://localhost:8081/
端口号可以在etc文件夹中 nexus-default.properties 配置。
管理员帐号的初始化密码在 sonatype-work\nexus3 中。
匿名访问设置
此处需要打勾,不然无法下载库

代理服务器
新建代理服务器,以阿里云为例。
阿里云的地址:http://maven.aliyun.com/nexus/content/groups/public/
自建服务器
自建服务器可以使用默认的maven-release
服务器组
工程引用:
maven { url "http://localhost:8081/repository/maven-public/" }
常用地址
aliyun(): http://maven.aliyun.com/nexus/content/groups/public/
aliyunjcenter():http://maven.aliyun.com/nexus/content/repositories/jcenter
google() : https://dl.google.com/dl/android/maven2/
mavenCentral() : https://repo1.maven.org/maven2/
jcenter() : http://jcenter.bintray.com/
jitpack: https://jitpack.io/
huawei:http://developer.huawei.com/repo
Google:https://maven.google.com/
umeng:https://dl.bintray.com/umsdk/release
另外还有本地的:
$rootDir/node_modules/react-native/android
引用lib
Gradle Groovy DSL原本工程引用的方式:
implementation project(path: ':MXKit')
可以在这里查看引用的方式
改为这种方式
implementation 'com.a.k:me:1.0.0'
其他引用方式
<dependency>
<groupId>com.a.b</groupId>
<artifactId>c</artifactId>
<version>1.0.0</version>
</dependency>
aar上传仓库
可以新建一个gradle文件,比如upload.gradle文件
内容如下:
apply plugin: 'maven'
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: 'http://localhost:8081/repository/maven-releases/') {
authentication(userName: 'admin', password: '123456')
}
pom.project {
version '1.0.0'
artifactId 'c'
groupId 'com.a.b'
packaging 'aar'
description 'xxxxxxxxx'
}
}
}
}
到需要上传库的module里面加入:
apply from: 'upload.gradle'

其他问题
问题一:刷新时不走代理服务器?
查看下是否使用了init.gradle,对链接进行了拦截
比如在路径下:C:\Users\Administrator.gradle\init.gradle
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')
|| url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url REPOSITORY_URL
}
}
}
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')
|| url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("allprojects ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url REPOSITORY_URL
}
}
}
}
问题二:部分库加载不到,比如
ERROR: Failed to resolve: BaseRecyclerViewAdapterHelper
Affected Modules: M
检查下依赖库
implementation ‘com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.40’
查看下目录,并没有下载到库
C:\Users\Administrator.gradle\caches\modules-2\files-2.1\com.github.CymChad\BaseRecyclerViewAdapterHelper
问题所在:
BaseRecyclerViewAdapterHelper库是托管在https://jitpack.io,因此需要再代理下此库。
并把库改为2.9.50即可解决。
问题三:上传aar是否会把依赖包也一起打包
只会把libs下面的包打包一起上传,但不会打包动态加载的第三方包。
如果是引用本地的库,例如:
api project(path: ':Kit')
那么最后在加载的时候,会出现
ERROR: Failed to resolve: Demo:kit:unspecified
Show in Project Structure dialog
Affected Modules: app
因此,上传aar的时候,务必检查依赖,把本地依赖全部改为远程依赖,或者是放入libs中。