Android 搭建私有maven仓库及上传项目
Nexus 介绍
Sonatype Nexus 是一个常见的搭建本地私有仓库的工具,详情进入官网查看https://www.sonatype.com/download-oss-sonatype
搭建私有Nexus仓库
下载 Nexus 安装包
https://www.sonatype.com/download-oss-sonatype
解压 Nexus 文件
## 启动 Nexus 服务
cd nexus-3.30.0-01/bin/
nexus start
1
➜ ~ /Users/xxxx/Downloads/nexus-3.30.0-01-mac/nexus-3.30.0-01/bin
➜ bin nexus start
Starting nexus
➜ bin
到此 Nexus 服务已经启动,访问 http://localhost:8081 即可访问 Nexus 私服,查看本地下载包内容 xxx.password
初始账户:admin
初始密码:admin123
Android Lib 发布私有仓库
1、根目录下配置build.gradle
maven {
url 'http://localhost:8081/repository/maven-public/'
credentials {
username = 'admin'
password = 'admin123'
}
}
2、在项目根目录下 gradle.properties 中添加配置:
仓库地址如下:
RELEASE_REPOSITORY_URL=http://localhost:8081/repository/maven-releases/
SNAPSHOT_REPOSITORY_URL=http://localhost:8081/repository/maven-snapshots/
GROUP_ID=com.example.test
ARTIFACT_ID=tesLib
USERNAME=admin
PASSWORD=admin123
VERSION=3.0.14-snapshots
Pandroid.debug.obsoleteApi=true
SHORT_VERSION=0
3、在项目根目录下添加gradle 的task 文件 upload.gradle 中添加配置:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
String vsion = project.SHORT_VERSION
System.out.println("======version:" + vsion)
pom.project {
groupId project.GROUP_ID
artifactId ARTIFACT_ID
version vsion
}
def rootProject = project.rootProject
pom.withXml {
it.asNode().dependencies.dependency.findAll {
it.groupId.text() == rootProject.name
}.each {
it.groupId.each {
it.value = rootProject.GROUP_ID
}
it.version.each {
it.value = vsion
}
}
}
repository(url: project.RELEASE_REPOSITORY_URL) {
authentication(userName: project.USERNAME, password: project.PASSWORD)
}
}
}
}
// 打包并上传源码
task generateSourcesJar(type: Jar) {
group = 'jar'
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives generateSourcesJar
}