//local.properties
sdk.dir=/Applications/ADT/sdk
bintray.user = ***
bintray.apikey = *************************
- 配置工程的build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
注意com.github.dcendents:android-maven-gradle-plugin名称和版本,引入android-maven-plugin和gradle-bintrayl-plugin 插件;
- 配置Module的build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// 提交到仓库中的版本号
version = "1.0.0"
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
}
def siteUrl = 'https://github.com/fyales/tagcloud' // 项目的主页
def gitUrl = 'https://github.com/fyales/tagcloud.git' // Git仓库的url
group = "com.fyales.android"
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name 'Android TagCloud' //项目描述
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 'fyales' //填写的一些基本信息
name 'fyales'
email 'fyales@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 = "TagCloud" //发布到JCenter上的项目名字
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
这串代码主要做了三件事
生成JavaDoc
生成Jar
配置我们项目的信息
在这里我要提醒一下,生成javadoc和jar是必选选项。一开始我认为做这些没有必要,所以没有写入生成javaDoc和jar的命令,于是,我收到了bintray的官方邮件(邮件中是另外一个项目):
Bintray (bintray) has sent you a direct message from Bintray:
Hi,
Jcenter hosts java applications that follows maven convention.
In addition to the .aar and pom files in the path: /com/fyales/parser/1.0.0
, your version should include a sources jar, and optionally a javadoc jar.
Your files should be under a maven path layout.
(see https://bintray.com/docs/usermanual/uploads/uploads_includingyourpackagesinjcenter.html)
Once those files are added, we'll be glad to include your package in JCenter.
Regards,
Bintray Support
在这边还有一个坑我写的javadoc命令一开始运行失败,这是因为我喜欢在我的注释这样写
@author fyales
@date
因为javadoc里面并没有@date,所以会解析失败,大家也要注意一下。。。。。。。
- 运行下面的命令将你的项目提交到Bintray
./gradlew bintrayUpload
- 提交审核
提交完成之后,你就可以申请你的项目到JCenter,点击Include My Package,在弹出的界面输入你的项目名称确定就可以了,当审核通过后,你就可以直接用你自己项目了.
- 引用
dependencies {
compile 'com.fyales.android:library:1.0.0'
}