使用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/ ...
随机推荐
- 2018-8-10-win10-uwp-横向-AppBarButton
title author date CreateTime categories win10 uwp 横向 AppBarButton lindexi 2018-08-10 19:16:50 +0800 ...
- linux用户的基本操作2 用户密码管理
目录 linux系统的基本用户操作2 用户的扩展知识 用户密码管理 linux系统的基本用户操作2 3)使用userdel删除账户 语法 : userdel [-r] username -r 同时删除 ...
- Mysql 事务相关
MySQL介绍 什么是MySQL? MySQL 是一种关系型数据库,在Java企业级开发中非常常用,因为 MySQL 是开源免费的,并且方便扩展.阿里巴巴数据库系统也大量用到了 MySQL,因此它 ...
- ivew Upload 上传时附带的额外参数
<Upload action="/api/device/importData" :data="uploadData" :before-upload=&qu ...
- 因为看见,所以发现:QBotVariant谢绝落幕
互联网给人带来便捷的同时,其公开大量的资源也同样给恶意利用者带了便捷,越来越多公开的恶意程序源码降低了对外攻击.入侵的难度,使得安全问题愈加严重. 阿里云安全团队从今年5月份监测到一BOT家族,其样本 ...
- PIC16F877A的TIME0学习
计算溢出时间根据晶振频率4Mhz,TMR0=6,PSA2~PSA0 = 1:4. 因为好像外部晶振在给PIC的时候多分了一次1:4.所以PSA2~PSA0取1:4刚好 数完250次的时间=(1/4Mh ...
- PCB一些设置记录
开始时设置原点,编辑>>原点>>设置 画PCB时,导入后,根据各个模块放好位置 设计>>类>>添加电源类 设计>>规则>>Cle ...
- 学习java web中的listener
web.xml里的顺序为:context-param->listener->filter->servlet 监听器是需要新建一个类,然后按监听的对象继承:ServletContext ...
- 工程师技术(五):Shell脚本的编写及测试、重定向输出的应用、使用特殊变量、编写一个判断脚本、编写一个批量添加用户脚本
一.Shell脚本的编写及测 目标: 本例要求两个简单的Shell脚本程序,任务目标如下: 1> 编写一个面世问候 /root/helloworld.sh 脚本,执行后显示出一段话“Hello ...
- 探索Redis设计与实现1:Redis 的基础数据结构概览
本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...