拥抱开源,热爱开源,将我们认为不错的代码开源到gihtub,将我们的库发布到jcenter\mevan等。
在根目录的gradle文件下加入
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
个人认为这1个最好保持一直。
最后我们根目录下的gradle文件变成这个样子
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
// 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
}
group = PROJ_GROUP
version = PROJ_VERSION
project.archivesBaseName = PROJ_ARTIFACTID
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += configurations.compile
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 PROJ_ARTIFACTID
}
}
artifacts {
archives javadocJar
archives sourcesJar
}
def pomConfig = {
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
developers {
developer {
id DEVELOPER_ID
name DEVELOPER_NAME
email DEVELOPER_EMAIL
}
}
//这里有引号,并且有个空格,否则生成不了依赖,主要是这里的dependencies并不是build.gradle里的dependencies,而gradle会把他当成自身的dependencies处理
"dependencies " {
// dependency{
// groupId "com.alibaba"
// artifactId "fastjson"
// "version " "1.2.6"
// //同dependencies
// }
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId PROJ_ARTIFACTID
pom{
packaging 'aar'
}
pom.withXml {
def root = asNode()
root.appendNode('description', PROJ_DESCRIPTION)
root.children().last() + pomConfig
}
}
}
}
bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty('BINTRAY_USER');
key = properties.getProperty('BINTRAY_KEY');
configurations = ['archives']
publications = ['mavenJava']
publish = true
pkg {
repo = 'maven'
name = PROJ_NAME
desc = PROJ_DESCRIPTION
websiteUrl = PROJ_WEBSITEURL
issueTrackerUrl = PROJ_ISSUETRACKERURL
vcsUrl = PROJ_VCSURL
licenses = ['Apache-2.0']
publicDownloadNumbers = true
}
}
上述文件几乎不用修改,假如你将要上传的包 包含其他的三方库。在以下块中进行申明
"dependencies " {
// dependency{
// groupId "com.alibaba"
// artifactId "fastjson"
// "version " "1.2.6"
// //同dependencies
// }
}
通俗易懂,一目了然,就不多做解释了。
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
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:23.1.1'
}
apply from:'../bintray.gradle'
注意bintray.gradle 一定要放在文件最下面。
BINTRAY_KEY=e21c3f96df17xxxxxxxx
BINTRAY_USER=guolei1130
这里对应的是bintray.gradle中的这一段代码,当然,你可以修改这段代码,将这2个属性写在任意位置
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty('BINTRAY_USER');
key = properties.getProperty('BINTRAY_KEY');
最后,sync now。
在model 对应的other task中,找到上面2个,点击生成 一般不慧出错
点击第二个即可
点击上图中的第一个task,如果出错,根据错误排查即可,一般就是身份验证的相关问题。
这个mevan仓库就是我刚才上传的,但是我们需要将他导入到jcenter 中,点击jcenter.点击有侧导入,筛选将要导入的库,等待管理员审核即可。
github地址,求个star
最后来张图证明我是刚刚上传的。
没错,就是这么so easy.