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

如有疑问欢迎交流

android studio发布公共类库到服务器maven仓库的更多相关文章

  1. 如何通过Android Studio发布library到jCenter和Maven Central

    http://www.jianshu.com/p/3c63ae866e52# 在Android Studio里,如果你想引入任何library到自己的项目中,只需要很简单的在module的build. ...

  2. Android Studio导入第三方类库的方法

    Android Studio导入第三方类库的方法 本人也刚刚开始尝试做android app的开发,听说android studio是Google支持的android 应用开发工具,所以想应该肯定比E ...

  3. Android Studio发布Release版本之坑--Unknown host 'd29vzk4ow07wi7.cloudfront.net'

    使用Android Studio发布Release版本时,出现Unknown host 'd29vzk4ow07wi7.cloudfront.net'...错误. 解决方法:修改本机的DNS为8.8. ...

  4. Android——Android Studio导入SlidingMenu类库的方法

    Android Studio导入SlidingMenu类库的方法(其他类库应该也适用)   本篇文章主要介绍了"Android Studio导入SlidingMenu类库的方法(其他类库应该 ...

  5. 如何将Android Studio与华为软件开发云代码仓库无缝对接(二)

    上篇文章:如何将Android Studio与华为软件开发云代码仓库无缝对接(一) 上一章讲了,如何用Android Studio以软件开发云代码仓库为基础,新建一个项目.接下来,这一章继续讲建好项目 ...

  6. Android Studio发布项目到jcenter,一行代码引入Module

    前面我们使用自己封装的okhttp项目时候,只需要app/build.gradle文件中加一行代码就能使用项目. compile 'com.ansen.http:okhttpencapsulation ...

  7. 建立企业内部mavenserver并使用Android Studio公布公共项目

    由于Android Studio使用了Gradle构建工具,在library依赖的处理上是将被依赖的library作为一个module引入(拥有一份完整的library拷贝),而Eclipse的ADT ...

  8. Android Studio导入第三方类库的方法(转)

    转自:链接 本人也刚刚开始尝试做android app的开发,听说android studio是Google支持的android 应用开发工具,所以想应该肯定比Eclipse好用吧,反正以前没有jav ...

  9. [Android Studio导入第三方类库方法] Error:(19, 23) 错误: 程序包org.apache.http不存在

    本文主要参考以下链接: http://m.blog.csdn.net/blog/BoxRice/48575027 https://drakeet.me/android-studio http://ww ...

随机推荐

  1. 【Linux】多进程与多线程之间的区别

    http://blog.csdn.net/byrsongqq/article/details/6339240 网络编程中设计并发服务器,使用多进程与多线程 ,请问有什么区别?  答案一: 1,进程:子 ...

  2. vue 之循环添加不同class

    在vue中按条件为class动态添加直接使用:class="[{ active: isActive }, errorClass]"之类的表达式就可以 但是如果我们要为一个循环列表按 ...

  3. Codeforces 932 C.Permutation Cycle-数学 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    C. Permutation Cycle   time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Java 界面编程【03】事件监听

    当你把界面都设计好了,总需要添加相应的执行动作给组件,在JAVA中有相应的时间处理机制,叫做“监听器”,给组件添加相应执行动作的过程叫做“注册”,其中的“监听器”是一个接口,里面包含了相应的执行函数, ...

  5. 第2章 Spring Boot 文档

    Spring Boot 文档 本节简要介绍了Spring Boot文档,是整个文档的参考指南. 您可以完整阅读本参考指南,或者如果您不感兴趣的话可以跳过该部分. 1. 关于文档 Spring Boot ...

  6. HDU5618 Jam's problem again

    CDQ分治模板题 #include<cstdio> #include<cctype> #include<algorithm> #include<cstring ...

  7. 为Jenkins增加ssl(https)的访问支持(Windows/Linux)

    前言: 增加ssl(https)的访问可以为部署在公网下的jenkins提供更安全的问题,最明显的好处应该是登录和jenkins-ci.jar的调用. 比如jenkins-ci.jar的调用,一般在w ...

  8. memcachq队列安装

    memcacheq是集中的队列小软件,使用起来简单,便捷,高效. 下载 http://git.oschina.net/sgfoot/linux-tools/raw/master/memcacheq-0 ...

  9. GO --微服务框架(一) goa

    当项目逐渐变大之后,服务增多,开发人员增加,单纯的使用go来写服务会遇到风格不统一,开发效率上的问题. 之前研究go的微服务架构go-kit最让人头疼的就是定义服务之后,还要写很多重复的框架代码,一直 ...

  10. Keras学习

    参加比赛用到了keras,虽然之前用tensorflow,但是感觉tensorflow的确不太友好,api比较难读,然后就学习keras使用 随着深入,发现keras的api确实比较友好 跑了一些ex ...