在上一篇中提到了怎么创建私有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。

如有疑问欢迎交流

最新文章

  1. Algorithms, Part I by Kevin Wayne, Robert Sedgewick
  2. ACM: 强化训练-百度之星-Problem C-字典树
  3. JavaScript系列:Date对象
  4. CSS3秘笈第三版涵盖HTML5学习笔记9~12章
  5. 【转】Oracle中dual表的用途介绍
  6. Com进程通信(有详细步骤)
  7. Ant快速入门(一)-----Ant介绍
  8. DeviceToken 获取失败,原因:Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串"...
  9. su Authentication failure解决
  10. .net 和java JSON 模板
  11. POJ3279 Catch That Cow(BFS)
  12. Linux查杀stopped进程
  13. ltp-ddt nor_mtd_dd_rw_jffs2
  14. MYSQL事务隔离级别详解附加实验
  15. Jmeter插件安装及使用
  16. Confluence 6 跟踪你安装中的自定义修改
  17. 关于react的一些东西
  18. NFS介绍 NFS服务端安装配置 NFS配置选项
  19. JS的作用域和声明提前
  20. 爬虫必备—scrapy-redis(分布式爬虫)

热门文章

  1. 23深入理解C指针之---数组的基础
  2. IC 拔取器 rework station
  3. Scrapy学习-11-Selector对象使用
  4. LightOJ 1140: How Many Zeroes? (数位DP)
  5. IOS 使用DSYM文件定位Bug 的具体位置
  6. kd树的构造与搜索
  7. HTML5 移动端头部标签
  8. BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
  9. chpasswd、dd命令、find实战、添加系统服务、buffer、cached
  10. Leetcode 数组问题3:旋转数组