使用Gradle发布项目到JCenter仓库 (转载)
这篇文章介绍通过Gradle把开源项目发布到公共仓库JCenter中,方便你我他的事情,我们都是很懒的嘛。JCenter现在是Android Studio中repositories的默认节点了,之前是Maven的,不过JCenter是兼容Maven的,所以放心使用。步骤基本是按Publishing Gradle Android Library to jCenter Repository这里来的,英文能看的直接看这篇也行。下面我的步骤正式开始,发布到JCenter仓库的是我的项目:BounceProgressBar。
申请Bintray账号
Bintray的基本功能类似于Maven Central,一样的我们需要一个账号,Bintray传送门,注册完成后第一步算完成了。
生成项目的JavaDoc和source JARs
简单的说生成的这两样东西就是我们在下一步中上传到远程仓库JCenter上的文件了。这一步需要android-maven-plugin插件,所以我们需要在项目的build.gradle(Top-level build file,项目最外层的build.gradle文件)中添加这个构建依赖,如下:
- buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0'
- classpath 'com.github.dcendents:android-maven-plugin:1.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
然后在你需要发布的那个module(我这里的即是library)的build.gradle里配置如下内容:
- apply plugin: 'com.android.library'
- apply plugin: 'com.github.dcendents.android-maven'
- apply plugin: 'com.jfrog.bintray'
- // This is the library version used when deploying the artifact
- version = "1.0.0"
- android {
- compileSdkVersion 21
- buildToolsVersion "21.1.2"
- resourcePrefix "bounceprogressbar__" //这个随便填
- defaultConfig {
- minSdkVersion 9
- targetSdkVersion 21
- versionCode 1
- versionName version
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.nineoldandroids:library:2.4.0+'
- }
- def siteUrl = 'https://github.com/zhengxiaopeng/BounceProgressBar' // 项目的主页
- def gitUrl = 'https://github.com/zhengxiaopeng/BounceProgressBar.git' // Git仓库的url
- group = "org.rocko.bpb" // Maven Group ID for the artifact,一般填你唯一的包名
- install {
- repositories.mavenInstaller {
- // This generates POM.xml with proper parameters
- pom {
- project {
- packaging 'aar'
- // Add your description here
- name 'Android BounceProgressBar Widget' //项目描述
- url siteUrl
- // Set your license
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- developers {
- developer {
- id 'zhengxiaopeng' //填写的一些基本信息
- name 'Rocko'
- email 'zhengxiaopeng.china@gmail.com'
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
- }
- }
- }
- }
- }
- task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
- }
- task javadoc(type: Javadoc) {
- source = android.sourceSets.main.java.srcDirs
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- }
- task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
- }
- artifacts {
- archives javadocJar
- archives sourcesJar
- }
- Properties properties = new Properties()
- properties.load(project.rootProject.file('local.properties').newDataInputStream())
- bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
- configurations = ['archives']
- pkg {
- repo = "maven"
- name = "BounceProgressBar" //发布到JCenter上的项目名字
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
- }
- }
配置好上述后需要在你的项目的根目录上的local.properties文件里(一般这文件需gitignore,防止泄露账户信息)配置你的bintray账号信息,your_user_name为你的用户名,your_apikey为你的账户的apikey,可以点击进入你的账户信息里再点击Edit即有查看API Key的选项,把他复制下来。
- bintray.user=your_user_name
- bintray.apikey=your_apikey
Rebuild一下项目,顺利的话,就可以在module里的build文件夹里生成相关文件了。这一步为止,就可以把你项目生成到本地的仓库中了,Android Studio中默认即在Android\sdk\extras\android\m2repository这里,所以我们可以通过如下命令(Windows中,可能还需要下载一遍Gradle,之后就不需要了)执行生成:
- gradlew install
上传到Bintray
上传到Bintray需要gradle-bintray-plugin的支持,所以在最外层的build.gradle里添加构建依赖:
- buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
- classpath 'com.github.dcendents:android-maven-plugin:1.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
Rebuild一下,然后执行如下命令(Windows中)完成上传:
- gradlew bintrayUpload
上传完成即可在Bintray网站上找到你的Repo,我们需要完成最后一步工作,申请你的Repo添加到JCenter。可以进入这个页面,输入你的项目名字点击匹配到的项目,然后写一写Comments再send即可,然后就等管理员批准了,我是大概等了40分钟,然后网站上会给你一条通过信息,然后就OK了,大功告成。

成功后就可以在其它项目里方便的使用你发布的项目了:
- dependencies {
- compile 'org.rocko.bpb:library:1.0.0'
- }
End
不明白的可以再看看这两篇文章或者留言。
相关文章:
使用Gradle发布Android开源项目到JCenter
Publishing Gradle Android Library to jCenter Repository
使用Gradle发布项目到JCenter仓库 (转载)的更多相关文章
- 如何在Android Studio中使用Gradle发布项目至Jcenter仓库
简述 目前非常流行将开源库上传至Jcenter仓库中,使用起来非常方便且易于维护,特别是在Android Studio环境中,只需几步配置就可以轻松实现上传和发布. Library的转换和引用 博主的 ...
- Android拓展系列(12)--使用Gradle发布aar项目到JCenter仓库
目的 发布自己的android library(也就是aar)到公共的jcenter仓库,所有的人都能用gradle最简单的方式引用. 为什么选择jcenter,它兼容maven,而且支持更多形式仓库 ...
- Android Studio发布项目到jcenter,一行代码引入Module
前面我们使用自己封装的okhttp项目时候,只需要app/build.gradle文件中加一行代码就能使用项目. compile 'com.ansen.http:okhttpencapsulation ...
- Gradle发布项目到 maven(1)
常见的 Maven 仓库 JCenter.MavenCenter.JitPack epositories { google() // google 仓库 jcenter() // JCenter 仓库 ...
- Android快速发布项目到jcenter详解
不管别人的教程多详细,都有他们忽略的坑,所以,都要自己动手.我也是参考了许多许多的博客,弄了一上午加下午十分钟,才搞定. 参考: 下面这个是大部分的步骤 http://blog.csdn.net/zh ...
- [Gradle] 发布构件到本地仓库
配置 需要发布构件的模块 build.gradle 加入如下配置 apply plugin: 'maven-publish' publishing { publications { mavenJava ...
- Gradle发布项目到 maven 之gradle-bintray-plugin(2)
上传的方式有两种,第一种是通过 bintray 官方出的插件 bintray/gradle-bintray-plugin 第二种是一个国外组织开源的插件 novoda/bintray-release ...
- Gradle发布项目到 maven 之novoda/bintray-release(3)
novoda/bintray-release 使用这个插件上传比较简单,只需要两步就可以 1.在项目根目录下的 build.gradle 添加插件依赖 // Top-level build file ...
- 使用IDEA 发布项目搭配远程仓库 Gitee
本次讲解的是idea 发布到gitee上 一样的操作流程 没有基础的请先去学习 附上我的 gitee 地址 有资源会发布到gitee 俗话说关注走一走 活到999 https://gitee.com/ ...
随机推荐
- 转载:java集合类数据结构分析
数组是 最常用的数据结构.数组的特点是长度固定,可以用下标索引,并且所有的元素的类型都是一致的.数组常用的场景有把:从数据库里读取雇员的信息存储为 EmployeeDetail[],把一个字符串转换并 ...
- PostgreSQL的学习-序列
序列对象(也叫序列生成器)都是用CREATE SEQUENCE创建的特殊的单行表.一个序列对象通常用于为行或者表生成唯一的标识符.下面序列函数,为我们从序列对象中获取最新的序列值提供了简单和并发读取安 ...
- 数据索引文件idx
数据索引文件idx 数据索引文件idx 数据索引文件idx
- jsp获取url路径的方法
如果你请求的URL是 http://localhost:8080/demo/Index.jsp request.getScheme() //输出:http request.getServerName ...
- Jquery中的offset()和position()深入剖析(元素定位)
先看看这两个方法的定义. offset(): 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整形属性:top 和 left.此方法只对可见元素有效. position(): 获取匹配元素相对父 ...
- subsequence 2
题目链接 题意:每次给出两个字母 和 只有这两个字母的原字符串的子序列,最后让你输出原字符串. 思路:先将字符转换为hash值,然后再转换成图,就是一个拓扑排序了,然后满足不了的情况有两种,一个是构造 ...
- 浏览器 url 编码
1.问题的由来 : http://www.ruanyifeng.com/blog/2010/02/url_encoding.html 2.网络标准RFC 1738做了硬性规定: 只有字母和数字[0-9 ...
- [MySQL] innobackupex在线备份及恢复(全量和增量)
安装percona-xtrabackup 方法1: percona-xtrabackup-2.1.9-744-Linux-x86_64.tar.gz(D:\share\src\linux-mysql) ...
- 2019 pycharm激活码
http://lookdiv.com 里面有,钥匙:1211268069 激活码网址里面有 lookdiv.com 里面的钥匙就是lookdiv.com
- Tomcat_shutdown
@echo off echo 执行开始时间 date/t time/t echo *********************************************** echo 正在关闭To ...