android studio发布公共类库到服务器maven仓库
2024-09-01 04:54:05
在上一篇中提到了怎么创建私有maven库,这篇主要结合android studio的使用,直接进入正题,看以下步骤
1.创建android项目
创建Project,然后加一个library的module,此处省略一万字了
2.配置gradle
在项目的gradle.properties里面配置基本信息
GROUP=对应maven的groupId值,如果名字中包含SNAPSHOT字符,项目将会发布到snapshots仓库,没有则发布到releases仓库
VERSION_NAME=对应maven的version值
POM_ARTIFACT_ID=对应maven的artifactId值
SNAPSHOT_REPOSITORY_URL=前面配置的snapshots仓库地址
RELEASE_REPOSITORY_URL=前面配置的releases仓库地址
NEXUS_USERNAME=登录nexus oss的用户名
NEXUS_PASSWORD=登录nexus oss的密码
在module的build.gradle末尾加入下面代码
apply plugin: 'maven'
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: RELEASE_REPOSITORY_URL) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
}
}
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
}
3.发布公共库
./gradlew clean build uploadArchives
就一条命令,最后成功就OK了,如果失败根据具体情况找原因。
然后到nexus上查看是否上传成功
4.使用
在project中的build.gradle中的allprojects->repositories加入
maven { url "http://192.168.59.103:8081/content/repositories/releases/" }
在module的build.gradle中的dependencies加入
compile 'groupId:artifactId:version'
groupId,artifactId,version换成你自己的 build一切OK。 如有疑问欢迎交流
最新文章
- Algorithms, Part I by Kevin Wayne, Robert Sedgewick
- ACM: 强化训练-百度之星-Problem C-字典树
- JavaScript系列:Date对象
- CSS3秘笈第三版涵盖HTML5学习笔记9~12章
- 【转】Oracle中dual表的用途介绍
- Com进程通信(有详细步骤)
- Ant快速入门(一)-----Ant介绍
- DeviceToken 获取失败,原因:Error Domain=NSCocoaErrorDomain Code=3000 ";未找到应用程序的“aps-environment”的授权字符串";...
- su Authentication failure解决
- .net 和java JSON 模板
- POJ3279 Catch That Cow(BFS)
- Linux查杀stopped进程
- ltp-ddt nor_mtd_dd_rw_jffs2
- MYSQL事务隔离级别详解附加实验
- Jmeter插件安装及使用
- Confluence 6 跟踪你安装中的自定义修改
- 关于react的一些东西
- NFS介绍 NFS服务端安装配置 NFS配置选项
- JS的作用域和声明提前
- 爬虫必备—scrapy-redis(分布式爬虫)