1. 程式人生 > >將你的程式碼上傳 Bintray 倉庫(轉)

將你的程式碼上傳 Bintray 倉庫(轉)

轉自:http://www.cnblogs.com/cpacm/p/5548241.html

在 Android Studio 中,我們通常可以利用 gradle 來匯入別人寫的第三方庫,通常可以簡單得使用一句話就能搞定整個導包過程,
比如:

compile 'net.cpacm.moneytext:moneyview:1.0.0'

在這個過程中,Android Studio 會從 Maven 倉庫伺服器中下載所對應的包。現在比較通用的兩個伺服器分別為 Jcenter 和 Maven Central。本文主要講的就是Jcenter了,Android Studio 預設使用的伺服器倉庫。

Jcenter

Jcenter 是 bintray.com 所使用的 Maven 倉庫。與 Maven Central 相比,jcenter 的速度更快,包含的庫更多,UI介面更友好,更容易使用,同時 bintray 還支援將 jcenter 上傳到 Maven Central 的功能。

 

語法規則

以前使用過 Maven 的可能會比較清楚,匯入的語句如何指向倉庫中唯一存在的庫。

compile 'net.cpacm.simpleslider:library:1.0.0'
compile 'GROUP_ID:ARTIFACT_ID:VERSION'

其中
GROUP_ID 是指包所在的組,比如我包放在 net.cpacm.simpleslider

中, 那麼我的 GROUP_ID 就是 net.cpacm.simpleslider
ARTIFACT_ID 是指工程名字,一般在android中都為library
VERSION 代表使用的包的版本。

Bintray 使用

登入後進入 Maven 倉庫建立要使用的包,同時填入相應的對應資訊。

Gradle 配置

首先確保你要上傳的第三方包是一個 library,作為一個專案的 module 存在。

project gradle

在 project gradle 中加入需要的依賴包

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5"

    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

local.properties

在專案的 local.properties 檔案裡面加入 api-key

bintray.user=YOUR_BINTRAY_USERNAME
bintray.apikey=YOUR_BINTRAY_API_KEY

 在 bintray 網站的個人資訊編輯頁可以找到。

對了,記得不要把 local.properties 傳到 github網站上導致個人資訊的洩露。

library gradle

修改 library 的 gradle 資訊

apply plugin: 'com.android.library'
// add plugin
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = '1.0.0'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
}

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
}

group = 'net.cpacm.simpleslider'
install {
    repositories.mavenInstaller {
        pom.project {
            packaging 'aar'
            groupId 'net.cpacm.simpleslider' //自己定義的組名
            artifactId 'library' 

            name 'simpleslider'
            description 'A simple slider allows you to easily use.'
            url 'https://github.com/cpacm/SimpleSlider'
            inceptionYear '2016'

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
            scm {
                connection 'https://github.com/cpacm/SimpleSlider.git'
                url 'https://github.com/cpacm/SimpleSlider'

            }
            developers {
                developer {
                    name 'cpacm'
                    email '[email protected]'
                }
            }
        }

    }
}

// Bintray

//獲取local.propertes的資訊
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream()) 

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    publish = true
    configurations = ['archives']
    pkg {
        //填入 bintray 上對應的 package 資訊
        repo = 'maven'
        name = 'SimpleSlider'
        vcsUrl = 'https://github.com/cpacm/SimpleSlider.git'
        websiteUrl = 'https://github.com/cpacm/SimpleSlider'
        licenses = ['Apache-2.0']
        issueTrackerUrl = 'https://github.com/cpacm/SimpleSlider/issues'
        publicDownloadNumbers = true
        version {
            name = '1.0.0'
            desc = 'simple slider release'
            vcsTag = '1.0.0'
            attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
        }
    }
}

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

task findConventions << {
    println project.getConvention()
}

安裝和上傳

在Android Studio Terminal視窗中執行命令

gradlew install
gradlew bintrayUpload

 至此已經打包上傳結束,可以回到 bintray 網站看看結果。

新增到Jcenter

點選上圖的 Add to jcenter 按鈕,向管理員申請新增到 jcenter 倉庫,一般等個幾小時就能通過。
最後在 https://jcenter.bintray.com 找到自己的庫就表示成功了。

相關推薦

程式碼 Bintray 倉庫

轉自:http://www.cnblogs.com/cpacm/p/5548241.html 在 Android Studio 中,我們通常可以利用 gradle 來匯入別人寫的第三方庫,通常可以簡單得使用一句話就能搞定整個導包過程, 比如: compile 'net.cpacm.moneytext:mon

文件的思考 http://blog.csdn.net/ncafei/article/details/53401961

內容 html csdn 大小寫 eva 最大 設備 改變 tar 文件上傳校驗 客戶端JavaScript校驗(一般只校驗後綴名) 一般都是在網頁上寫一段javascript腳本,校驗上傳文件的後綴名,有白名單形式也有黑名單形式。  判斷方式:在瀏覽加載文

SpringMVC-實現PUT請求文件

Enctype multi think pic 不可 form OS his win 因為在圖片上傳的時候使用的是二進制的方式上傳,所以使用隱藏域進行方法轉換方式失效,轉方法: https://www.cnblogs.com/morethink/p/6378015.html

springmvc+mybatis+html 下查詢數據以excell形式到ftp

throws enabled con use ntc row buffered quest tp服務器 上節講到的是從數據庫中查詢相應的結果以excell形式寫到ftp服務器上,今天又試了試從ftp上將excell 文件下載到本地目錄,一開始的時候遇到了中文亂碼問題,文件名

】使用git項目到github最簡單方法

名稱 posit gitignore nor this strong 共享 window mas 原文地址:http://www.cnblogs.com/cxk1995/p/5800196.html 首先你需要一個github賬號,所有還沒有的話先去註冊吧! https:/

使用git專案程式碼到github流程

用git將專案程式碼上傳到github流程   先上常用語句 git add . git commit -m "img commit" $ git pull $ git push -u or

c#本地檔案至伺服器內網

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; u

如何個人程式碼到github

gitHub是一個面向開源及私有軟體專案的託管平臺,因為只支援git 作為唯一的版本庫格式進行託管,故名gitHub。git和svn一樣是一個很好用的版本管理工具。 github有什麼用?比如託管程式碼、製作靜態頁面、分享程式碼、託管靜態檔案,如個人簡歷,css、js等,也可在上面找一些

微信小程式學生資訊到阿里雲資料庫

//上傳 function upload(that,id){ if(that.data.imageList.length==0){ return; } wx.uploadFile({ url:"http://lichenlu.top/serv

Git學習系列之如何正確且高效地本地專案到Github圖文詳解

  不多說,直接上乾貨!   首先你需要一個Github賬號,所以還沒有的話先去註冊吧! https://github.com/   見   Git的安裝   見 1、進入Github首頁,點選New repository新建一個

用gitbash專案程式碼到GitHub

配置Git 我們先在電腦硬盤裡找一塊地方存放本地倉庫,比如我們把本地倉庫建立在C:\MyRepository\1ke_test資料夾下 進入1ke_test資料夾 滑鼠右鍵操作如下步驟: 1)在本地倉庫裡右鍵選擇Git Init Here,會多出來一個.git資料夾,這就表示本地git建立成功。右

Git的使用--如何本地專案到Github兩種簡單、方便的方法

將本地專案上傳到Github(兩種簡單、方便的方法) 一、第一種方法: 首先你需要一個github賬號,所有還沒有的話先去註冊吧! https://github.com/ 我們使用git需要先安裝git工具,這裡給出下載地址,下載後一路直

使用git項目到github最簡單方法

就會 接下來 this src name 操作 生成文件 選擇 gin 首先你需要一個github賬號,所有還沒有的話先去註冊吧! https://github.com/ 我們使用git需要先安裝git工具,這裏給出下載地址,下載後一路直接安裝即可: https://git

如何用git專案程式碼到github

配置Git 我們先在電腦硬盤裡找一塊地方存放本地倉庫,比如我們把本地倉庫建立在C:\MyRepository\1ke_test資料夾下 進入1ke_test資料夾 滑鼠右鍵操作如下步驟: 1)在本地倉庫裡右鍵選擇Git Init Here,會多出來一個.git資料夾,這就表示本地git建立成功。右

struts2學習(13)struts2文件和下載1

action alt for ide 上傳文件 fig .org dac str 一、Struts2文件上傳: 二、配置文件的大小以及允許上傳的文件類型: 三、大文件上傳: 如果不配置上傳文件的大小,struts2默認允許上傳文件最大為2M; 2097152Byte;

struts2學習(14)struts2文件和下載4多個文件和下載

sym ring spl out urn ide http iso length 四、多個文件上傳: 五、struts2文件下載: 多個文件上傳action com.cy.action.FilesUploadAction.java: package com.cy.a

servlet文件

https 創建 res exception threshold poi rac body urn 1.servlet上傳文件   servlet上傳文件就是將客戶端的文件上傳到服務器端。   向服務器發送數據時,客戶端發送的http請求正文采用“multipart/for

js文件圖片限制格式及大小為3M

max element 不能 jpg script 圖片大小 -s 打開 -1 本文保存為.html文件用瀏覽器打開即可測試功能 <form id="form1" name="form1" method="post" action="" enctype="m

springboot下載檔案3--java api 操作HDFS叢集+叢集配置

 只有光頭才能變強! 前一篇文章講了nginx+ftp搭建獨立的檔案伺服器 但這個伺服器宕機了怎麼辦? 我們用hdfs分散式檔案系統來解決這個問題(同時也為hadoop系列開個頭) 目錄 1、Ubuntu14.04下配置Hadoop(2.8.5)叢集環境詳解(完全分

SpringMVC篇:轉發與重定向、圖片檔案、Jsonjackson

注意: 專案:war 和 專案:war  exploded 兩者並不同,idea  執行 專案:war  exploded   <dependency> <groupId>org.