简书地址:http://www.jianshu.com/p/fd2f2eca63b7
过程比较简单,记录一下发布的流程,方便后续查阅
1.注册登录就不多说了JCenter地址
2.新建一个项目GradlePro,同时新建一个module
3.编辑项目的根目录中的build.gradle文件
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
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
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
4.编辑Module(对应此项目中的exlibrary)中的build.gralde文件
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
//版本号
version = "1.0.0"
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
//资源前缀
resourcePrefix "exlibrary__"
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
lintOptions {
abortOnError false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
//项目的主页
def siteUrl = 'https://github.com/byhook/GradlePro'
//Git仓库主页
def gitUrl = 'https://github.com/byhook/GradlePro.git'
//Maven Group ID
group = "cn.byhook.exlibrary"
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
//项目描述
name 'Android ExLibrary'
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 'byhook'
name 'Andy'
email 'byhook@163.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"
//发布到JCenter上的项目名称
name = "ExLibrary"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
5.编辑local.properties新增配置
bintray.user=your_username
bintray.apikey=your_apikey
6.上传到Bintray需要gradle-bintray-plugin的支持,在项目根目录的build.gradle中新增依赖
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
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
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
7.在项目根目录执行命令
gradle clean
gradle build --info
即可生成所需要的文件
8.开始发布项目,先登录JCenter,拷贝你自己的ApiKey,写进刚才的配置文件local.properties中去
在根目录输入命令开始上传
gradle bintrayUpload
9.进入JCenter后台配置
点击进入,可以看到我们发布的项目啦
10.进入详情,点击添加到JCenter中去
填写号相应的Comments信息,点击Send然后就等待审核完成了
小结:
1.Windows下的命令貌似是gradlew开头的
2.之前在根目录下配置build.gradle,
使用这个没有通过
classpath 'com.github.dcendents:android-maven-plugin:1.2'
改成这个就好了
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'