使用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/ ...
随机推荐
- Python向方法中传递自定义类型参数
定义类型 class Fish: def __init__(self,x): self.num = xclass Turtle: def __init__(self,y): self.num = yc ...
- 【串线篇】MyBatis简介
一.MyBatis 和数据库进行交互:持久化层框架(SQL映射框架): 1).纯手工 从原始的JDBC----dbutils(QueryRunner)-------JdbcTemplate----xx ...
- Python3.5-20190507-廖老师-自我笔记-迭代
可以使用for x in 数据 的那么 这个数据就是可迭代对象. 通过计算生成下一个值的数据就是生成器 可以使用next(数据) 来计算出下一个值的数据就是迭代器(生成器属于迭代器) -------- ...
- Qt pro使用sql之类的需要添加的模块
举个栗子,当要使用QSqlQuery 的时候需要在pro中添加Qt +=sql 然后在.h里面#include<QSqlQuery>即可使用sql. 同理要使用media或者net的时候只 ...
- css雪碧图实现数字切换
vue中 css 雪碧图应用及数字切换demo 1. CSS Sprites一般只能使用到固定大小的盒子(box)里,这样才能够遮挡住不应该看到的部分. 2.使用css雪碧图的优点: 利用CSS Sp ...
- 监控服务(keepalived,httpd)
#!/bin/bashpidof httpdif [ $? -eq 0 ];then echo "httpd is ok"else echo "httpd is not ...
- activemq消息中间件的依赖
<dependencies> <dependency> <groupId>org.apache.activemq</groupId> <artif ...
- linux su su-的区别
su只是切换用户. su - 切换用户并切换shell环境. su another pwd后为/home/current su - another pwd后为/home/another
- 2019 TCO Round 1B——[ 状压DP ]
第一题是 EllysSki . 题意:给n个数,求两个方向的最长递减区间. 可以O(n). #include<cstdio> #include<cstring> #includ ...
- [CSP-S模拟测试]:玄学题/c(数学)
题目传送门(内部题40) 输入格式 第一行:两个正整数$n$.$m$. 输出格式 第一行:一个整数,代表式子的值. 样例 样例输入1: 4 5 样例输出1: 0样例输入2: 799 8278 样例输出 ...