将你的代码上传 Bintray 仓库
在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单得使用一句话就能搞定整个导包过程,
比如:
compile 'net.cpacm.moneytext:moneyview:1.0.0'
在这个过程中,Android Studio 会从 Maven 仓库服务器中下载所对应的包。现在比较通用的两个服务器分别为 Jcenter 和 Maven Central。本文主要讲的就是Jcenter了,Android Studio 默认使用的服务器仓库。
Jcenter
Jcenter 是 bintray.com 所使用的 Maven 仓库。与 Maven Central 相比,jcenter 的速度更快,包含的库更多,UI界面更友好,更容易使用,同时 bintray 还支持将 jcenter 上传到 Maven Central 的功能。

语法规则
以前使用过 Maven 的可能会比较清楚,导入的语句如何指向仓库中唯一存在的库。
compile 'net.cpacm.simpleslider:library:1.0.0'
compile 'GROUP_ID:ARTIFACT_ID:VERSION'
其中
GROUP_ID 是指包所在的组,比如我包放在 net.cpacm.simpleslider 中, 那么我的 GROUP_ID 就是 net.cpacm.simpleslider。
ARTIFACT_ID 是指工程名字,一般在android中都为library。
VERSION 代表使用的包的版本。
Bintray 使用
请科学上网
bintray 支持 github 和 google+ 第三方直接登录。

登录后进入 Maven 仓库建立要使用的包,同时填入相应的对应信息。




Gradle 配置
首先确保你要上传的第三方包是一个 library,作为一个项目的 module 存在。
project gradle
在 project gradle 中加入需要的依赖包
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5"
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
local.properties
在项目的 local.properties 文件里面加入 api-key
bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY
在 bintray 网站的个人信息编辑页可以找到。

对了,记得不要把 local.properties 传到 github网站上导致个人信息的泄露。
library gradle
修改 library 的 gradle 信息
apply plugin: 'com.android.library'
// add plugin
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = '1.0.0'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
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
}
group = 'net.cpacm.simpleslider'
install {
repositories.mavenInstaller {
pom.project {
packaging 'aar'
groupId 'net.cpacm.simpleslider' //自己定义的组名
artifactId 'library'
name 'simpleslider'
description 'A simple slider allows you to easily use.'
url 'https://github.com/cpacm/SimpleSlider'
inceptionYear '2016'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'https://github.com/cpacm/SimpleSlider.git'
url 'https://github.com/cpacm/SimpleSlider'
}
developers {
developer {
name 'cpacm'
email 'shenliming@gmail.com'
}
}
}
}
}
// Bintray
//获取local.propertes的信息
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
publish = true
configurations = ['archives']
pkg {
//填入 bintray 上对应的 package 信息
repo = 'maven'
name = 'SimpleSlider'
vcsUrl = 'https://github.com/cpacm/SimpleSlider.git'
websiteUrl = 'https://github.com/cpacm/SimpleSlider'
licenses = ['Apache-2.0']
issueTrackerUrl = 'https://github.com/cpacm/SimpleSlider/issues'
publicDownloadNumbers = true
version {
name = '1.0.0'
desc = 'simple slider release'
vcsTag = '1.0.0'
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
task findConventions << {
println project.getConvention()
}
安装和上传
在Android Studio Terminal窗口中运行命令
gradlew install
gradlew bintrayUpload
至此已经打包上传结束,可以回到 bintray 网站看看结果。

添加到Jcenter
点击上图的 Add to jcenter 按钮,向管理员申请添加到 jcenter 仓库,一般等个几小时就能通过。
最后在 https://jcenter.bintray.com 找到自己的库就表示成功了。
作者:cpacm
参考资料:http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
地址:将你的代码上传 Bintray 仓库
将你的代码上传 Bintray 仓库的更多相关文章
- 将你的代码上传 Bintray 仓库(转)
转自:http://www.cnblogs.com/cpacm/p/5548241.html 在 Android Studio 中,我们通常可以利用 gradle 来导入别人写的第三方库,通常可以简单 ...
- (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库
(超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库 本地创建了一个 xcode 工程项目,现通过 命令行 将该项目上传到 github 或者 gitlab 远程仓库,具体 ...
- IDEA新项目代码上传到gitlab远程仓库
IDEA新项目代码上传到gitlab远程仓库 具体步骤 创建本地仓库 IDEA:VCS-->Import into Version Control-->Create Git Reposit ...
- github将本地仓库的代码上传到Github
本篇主要参考博文:https://blog.csdn.net/IT_faquir/article/details/52516214 你要先完成上一篇的操作,即将代码上传到本地仓库中,才能上传到gith ...
- 代码上传多个git仓库,切换过remote后导致 can't update
问题描述: 因为代码上传到github和coding 切换了 git--> rmote的地址:后来update失败 问题解决: 重新配置git解决:按提示操作就好 git fetch git p ...
- git使用之如何将github库下载到本地与如何将代码上传github
git使用之如何将github库下载到本地与如何将代码上传github ---------------------------------------------------------------- ...
- java~gradle构建公用包并上传到仓库
java~gradle构建公用包并上传到仓库 我们一般会把公用的代码放在一个包里,然后其它 项目可以直接使用,就像你使用第三方包一样! 仓库 存储包的地方叫做仓库,一般可以分为本地仓库和远程仓库,本地 ...
- 如何用git将项目代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- mac上将代码上传到github
前言 有时我们会写一些小程序来学习新的知识,但是完事之后过一段时间可能会忘记,最好的办法就是找到原来的代码看一看.现在可以将代码免费托管到一些网站上,其中最著名的非github莫属了, 今天就把这个过 ...
随机推荐
- Silverlight开源框架SL提供便捷的二次开发银光框架
Silverlight开发框架SilverFrame欢迎咨询 基于Silverlight4.0开发,兼容Silverlight 5.0,SQLServer2005数据库.WCF: 本框架有清爽的前端界 ...
- bzoj3136
Description 给定m个素数和Q个询问.每个询问有n个人,每次操作可以任意选择其中的一个素数p(素数可以重复使用),然后去掉剩余人数 mod p个人.对于每个询问,我们想知道,至少需要多少步操 ...
- define宏定义中的#,##,@#及\符号
define宏定义中的#,##,@#及\符号 在#define中,标准只定义了#和##两种操作.#用来把参数转换成字符串,##则用来连接两个前后两个参数,把它们变成一个字符串. 1.# (string ...
- IOS开发之自定义系统弹出键盘上方的view(转载)
这篇文章解决的一个开发中的实际问题就是:当弹出键盘时,自定义键盘上方的view.目前就我的经验来看,有两种解决方法.一个就是利用UITextField或者UITextView的inputAccesso ...
- ROM, RAM, Flash Memory
ROM Read-only memory (ROM) is a class of storage medium used in computers and other electronic devic ...
- aptana studio 3 自动换行(无需插件)
菜单-Window-Preferences-Aptana Studio-Editors,勾选“Enable word wrap”,然后重启编辑器.
- spark on hive 配置hive的metastore为mysql
<property><name>hive.metastore.uris</name><value></value><descripti ...
- AP_应付税务预扣税Withholding Tax中付款时产生预扣税(案例)
2014-07-12 Created By BaoXinjian
- POJ-2752 Seek the Name, Seek the Fame(KMP,前缀与后缀相等)
题意: 给出一个字符串str,求出str中存在多少子串,使得这些子串既是str的前缀,又是str的后缀.从小到大依次输出这些子串的长度. 这个就是next数组的应用,next数组真是很深奥啊. ...
- NeHe OpenGL教程 第四课:旋转
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...