首先看看有這幾個文件:
屏幕快照 2017-10-24 20.19.57.png
上圖的bintray.data.gradle,bintray.gradle和install.gradle其他項目也可以復用,只要修改bintray.data.gradle中相關的信息就可以了,非常簡單。
- bintray.data.gradle(寫你自己的配置)
ext {
bintrayRepo = 'maven' //jcenter上的倉庫名,習慣用maven
bintrayName = 'imagepickermaster' //發布到JCenter上的項目名字
bintrayUserOrg = 'supertxy' //jcenter 上的用戶名
publishedGroupId = 'com.github.SuperTxy' //groupId
libraryName = 'imagepickermaster' //name
artifact = 'imagepickermaster'
libraryDescription = "image picker with video"
siteUrl = 'https://github.com/SuperTxy/imagerpickermaster'
gitUrl = 'https://github.com/SuperTxy/imagerpickermaster.git'
libraryVersion = 'v1.6.5'
developerId = 'SuperTxy'
developerName = 'xxx'
developerEmail = 'xxxx@gmail.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
- bintray.gradle(配置bintray,一些task)
apply plugin: 'com.jfrog.bintray'
apply from: './bintray.data.gradle'
version = libraryVersion
if (project.hasProperty("android")) { // Android libraries
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc) {
options.addBooleanOption('Xdoclint:none', true)
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
} else { // Java libraries
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 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 = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
}
}
- install.gradle(關于install的)
apply plugin: 'com.github.dcendents.android-maven'
apply from: './bintray.data.gradle'
group = publishedGroupId
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact
name libraryName
description libraryDescription
url siteUrl
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
接下來在下面的文件中加入相對的內容
- 在自己的library的build.gradle中加入:
apply from: './install.gradle'
apply from: './bintray.gradle'
- 在root build.gradle中加入
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
}
- 在local.properties中加入自己在jcenter上的用戶名和apikey
bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY
接下來是上傳了
在終端Terminal中輸入 ./gradlew install 如果沒有問題,再輸入 ./gradlew bintrayUpload上傳到jcenter就行了。
關于jcenter帳號的注冊和maven 倉庫的創建我就不再贅述了。