將Android Studio開源項目提交到JCenter

  • bintray註冊帳號;
  • edit記住你的name和API KEY,能夠把這些信息放在local.properties文件中;
//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 插件;html

  • 配置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

    }

}

這串代碼主要作了三件事java

生成JavaDocandroid

生成Jargit

配置咱們項目的信息github

在這裏我要提醒一下,生成javadoc和jar是必選選項。一開始我認爲作這些沒有必要,因此沒有寫入生成javaDoc和jar的命令,因而,我收到了bintray的官方郵件(郵件中是另一個項目):web

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命令一開始運行失敗,這是由於我喜歡在個人註釋這樣寫apache

@author fyales

@date

由於javadoc裏面並無@date,因此會解析失敗,你們也要注意一下。。。。。。。api

  • 運行下面的命令將你的項目提交到Bintray
./gradlew bintrayUpload
  • 提交審覈

提交完成以後,你就能夠申請你的項目到JCenter,點擊Include My Package,在彈出的界面輸入你的項目名稱肯定就能夠了,當審覈經過後,你就能夠直接用你本身項目了.app

  • 引用
dependencies {

    compile 'com.fyales.android:library:1.0.0'

}
相關文章
相關標籤/搜索