作用
- 节省自己的外网宽带
- 加速构建过程
- 部署第三方构件
- 提高稳定性,增强控制
- 降低中央仓库的负荷
步骤
- (win环境)下载nexus 2.切换到bin目录下执行nexus /run 3.浏览器输入http://localhost:8081/打开
4.登录账号
默认账号名:admin
密码:在此路径下
某盘:\nexus-3.19.1-01-win64\sonatype-work\nexus3\admin.password
4.创建Repositorie
5.复制maven地址
6.根目录gradle文件中添加仓库
repositories { //为gradle构建添加仓库
maven {
url 'http://localhost:8081/repository/test_releases/'
credentials {
username 'admin'
password 'admin'
}
}
maven {
url 'http://localhost:8081/repository/test_snapshots/'
credentials {
username 'admin'
password 'admin'
}
}
google()
jcenter()
}
}
allprojects { //为工程添加仓库
repositories {
maven {
url 'http://localhost:8081/repository/test_releases/'
credentials {
username 'admin'
password 'admin'
}
}
maven {
url 'http://localhost:8081/repository/test_snapshots/'
credentials {
username 'admin'
password 'admin'
}
}
}
}
- 根目录gradle.properties中配置常量方便设置
NEXUS_REPOSITORY_URL=http://localhost:8081/repository/imooc-snapshots/
#组名
POM_GROUPID=com.test.android
#类型 aar/jar等等
POM_PACKAGING=aar
NEXUS_USERNAME=用户名
NEXUS_PASSWORD=密码
- 子module build.gradle中配置maven上传
plugins {
id 'com.android.library'
id 'maven' //配置插件
}
//定义变量
def pomName = this.getName()
def pomVersionName = '1.0.0-SNAPSHOT'
def pomDescription = 'the audio library for all project'
android {
//省略
}
dependencies {
//省略
}
//上传maven配置
uploadArchives {
repositories {
mavenDeployer {
repository(url: NEXUS_REPOSITORY_URL) { //配置snapshots URL
//配置用户名/密码
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
pom.project {
name pomName
version pomVersionName
description pomDescription
artifactId pomVersionName
groupId POM_GROUPID
packaging POM_PACKAGING
}
}
}
}