前言
最近想上传一个项目到 jcenter() 当中。踩了不少坑,在此记录一下。
账号注册
点击此处注册链接:点我注册
如下图:

点击 SIGN UP FOR AN OPEN SOURCE ACCOUNT 注册个人账号

- FirstName : 名 LastName: 姓 (这两个你可以随便输入,之后可以更改)
- UserName : 登录使用的用户名 (想好了再输入,不能更改哦!!!)
- Password : 密码
- Email Address : 邮箱地址 (建议你Google 邮箱) 。
- Select Country : 选择国家
然后点击 Create My Account 成功注册。
创建仓库
如下图,点击 View Profile

点击 Add New Repository

输入相关信息:

Name : 填入 maven 。
Type : 选择 Maven 。
Default Licenses : 可不用填写(之后可以改动)
Description (Optional) : 描述 (也可不用填写,之后可以改动)
然后点击下方 Create , 仓库创建完毕 。
获取AppKey

插件依赖
在项目最外层的build.gradle添加“gradle-bintray-plugin”以及“android-maven-plugin”插件的依赖。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Gradle配置
在项目的根目录下,新建bintray.gradle文件,内容如下:
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "0.6.1" // 版本号
def siteUrl = 'https://github.com/jeasonlzy/ImagePicker' // Git项目主页
def gitUrl = 'https://github.com/jeasonlzy/ImagePicker.git' // Git仓库url
group = "com.lzy.widget" // 一般为包名
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name 'ImagePicker For Android' // 项目描述
url siteUrl
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'jeasonlzy' // 开发者信息
name 'LiaoZiYao' // 开发者信息
email 'liaojeason@126.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
}
javadoc {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/7/docs/api"
title 'ImagePicker For Android' // 文档标题
}
}
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 = "imagepicker" // 数据仓库依赖第二部分
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
配置Username和APIKey
在local.properties文件配置Username和APIKey。
bintray.user = xxx
bintray.apikey = xxx
上传到JCenter
在Android Studio的Terminal执行以下命令:
gradlew javadocJar
gradlew sourcesJar
gradlew install
gradlew bintrayUpload
审核
上传成功后,并不能立即通过 Gradle 使用 ,还需要审核 。 进入你的仓库,点击进入你的项目。

点击进去可看到刚刚上传的项目。
项目加入Jcenter
申请地址:https://bintray.com/bintray/jcenter
搜索刚刚上传的项目,并选中。或者进入项目主页,点击右下角“Add to Jcenter”

输入项目描述,完成。
现在有更好的依赖方式,直接上传GitHub项目到JitPack,请参考
本文详细介绍如何将项目上传至JCenter的过程,包括账号注册、仓库创建、AppKey获取及Gradle配置等步骤,并提供了实用的命令行指令帮助快速完成上传。
1万+

被折叠的 条评论
为什么被折叠?



