Bintray网页操作
- 一定要在下面这个网址注册(个人账户)
https://bintray.com/signup/oss - 不要在这里注册 https://bintray.com(这是公司组织注册的账户)
- 用github或者谷歌邮箱注册,不能使用国内邮箱
创建一个组织



在该组织下创建仓库


至此,组织–>仓库 创建好了

获取key和user
拿到这些信息,gradle配置会用到

代码gradle配置
简介
在项目根目录下的 local.properties 中填写我们的 user 和 API key,这里的内容是完全可以放在 gradle.properties 中的,但是通常我们的开源库都会发到 Github 的公共仓库中,如果这样的话那我们的 API key 就会暴露给其他人,那当然是不行的,所以我们就在 git 忽略的 local.properties 中配置我们的 API key。
BINTRAY_USER=werbhelius
BINTRAY_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

- 项目根gradle添加
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'

2.Module的gradle配置
这里向大家介绍一下 aar 和 jar 的区别。
.jar :只包含了 class 文件与清单文件,不包含资源文件,如图片等所有 res 中的文件。
.aar:包含所有资源,class** 以及 res 资源文件全部包含。
如果你只是一个简单的类库那么使用生成的 *.jar文件即可;如果你的是一个UI库,包含一些自己写的控件布局文件以及字体等资源文件那么就只能使用 *.aar 文件。
在我们开源库的目录下,新建一个 bintray.gradle 文件,用于上传开源库以及配置发布的文件内容包括源码,文档以及 AAR。
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
//上传到Jcenter 相关配置 以下配置都需要修改成自己的数据
def siteUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample' // # 项目的主页
def gitUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample' // # Git仓库的url
def issueUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample/issues' // # Git仓库issues的url
//参考 compile 'groupId:artifactId:version',groupId就是group version下面的版本
group "com.github.wang" //groupId
version = "1.0.0" // # 发布版本号
def artifactIdName = 'local-broadcast-compiler'// # artifactId
def projectName = 'broadcastCompiler' // #这个是显示在bintray 仓库中的项目名字,一般可用项目名称
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 = projectName //这个是显示在bintray 仓库中的项目名字,一般可用项目名称
websiteUrl = siteUrl
vcsUrl = gitUrl
issueTrackerUrl = issueUrl
userOrg = "wangwei15" //组织名 需要和建组织用的名字一致
//自己创建的organization名称,一定要全是小写字母,即使当时创建的名称含有大写,这里全部转换为小写,否则404
licenses = ['MIT']//不能随便写,只能是仓库创建时选择的license type
publish = true// 是否是公开项目,公开别人可以引用
}
}
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
name artifactIdName //project.name的属性值建议与project.artifactId一致
artifactId artifactIdName //依赖包最后面的部分
description 'A android lib allows you to easily use.'
url siteUrl
// Set your license
licenses {
license {
name 'MIT' //和之前自己定义的协议一致
url 'https://raw.githubusercontent.com/minggo620/Pluto-Android/master/LICENSE'
}
}
developers {
developer {
id 'wangwei' //填写的一些基本信息
name '王伟'
email '709693972@qq.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
if (project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library')) {
println('--------android--------')
//android javadoc和sources文件的生成
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false //必须添加以免出错
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
}
} else {
println('--------java--------')
//java javadoc和sources文件的生成
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
}
artifacts {
archives sourcesJar
archives javadocJar
}
//在构建生成的时候有可能会报GBK编码等错误,可能需要添加UTF-8声明,如下:
javadoc {
options {
//如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/7/docs/api"
}
}
3.在我们开源库中的 build.gradle 文件中引入 bintary.gradle ,注意引入的命令需要写在最后一行,不然会报错。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply from: './bintray.gradle'
4.当上述的配置全部完成之后,我们可以上传我们的开源库了,打开 Terminal,执行 ./gradlew install,执行完成后,打开 build 目录你会发现生成了 aar 包、javadoc 文档、sources 源码以及上传 maven 需要的 pom 配置文件。
5.生成上述文件后,继续在 Terminal 中执行 ./gradlew bintrayUpload 提示成功之后,我们的开源库就发布成功啦。
发布成功之后,打开之前 bintray 网页,你会发现在之前我们创建的 maven 仓库中,已经有我们刚刚发布的库了。

发布到 JCenter
在 bintray 开源库的网页中,右边会有 Add to JCenter 的提示,点击提交 commit 就可以啦,一般在几个小时或一天的时间就会提示你添加成功。

问题记录
1、https://www.jianshu.com/p/9c6ac57e80f4
2、第一次必须要发布审核才能使用 审核期间 可以在根目录的build 里面依赖自己的mavan 仓库使用
maven {
url 'https://dl.bintray.com/wangwei15/maven/'
}
上传JCenter 步骤
1、根目录build 添加
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
2、修改 local.properties 用户名称及key
3、我们开源库中的 upload_bintray.gradle 文件中引入 bintary.gradle ,注意引入的命令需要写在最后一行,不然会报错。
4、修改上述文件#号注释的地方
5、执行 gradlew install 用于将项目编译、打包生成 pom,aar 等文件;
6、执行 gradlew bintrayUpload 用于将生成的 pom,aar 等文件上传至 bintray 仓库中;
7、如果是第一次上传 需要发布到 JCenter ,Add to JCenter 的提示,点击提交 commit 就可以啦
网友评论