Maven Centralは拝承しないといけなくて面倒だ、Bintrayは何か適当にアップ出来るらしいという事でBintrayに飛びついたのですがリポジトリにライブラリをアップする手順が難解で挫折し続けていました。途方に暮れていた所社内で以下のBintrayのページとリポジトリを教えてもらいました。
bintray/bintray-examples · GitHub
中の人が色んなパターンのファイルをBintrayにアップする方法を書いたサンプル集です。サイコー。gradle-aar-example
ってのもあってホントにサイコーです。
AndroidのライブラリをBintrayにアップする
bintray-examples/gradle-aar-example at master · bintray/bintray-examples · GitHubを読めば分かるんですが一応手順をメモっときます。
Bintrayのアカウントを作る
とりあえずBintrayのアカウントを作りましょう。フリーでは500MBのスペースを得られます。
API Keyを確認する
アカウントを取ったらBintrayのmaven repositoryにファイルをアップロードする時に必要なAPI Keyを確認します。
自分のプロフィール画面を開き、Editから編集画面へ行きます。
編集画面にAPI Key
という項目があります。
gradle.propertiesに設定を書く
あとはGradle用の設定を書くだけです。Bintrayにファイルをアップロードする為に必要なuser名とAPI Keyをgradle.propertiesに記述します。この時gradle.propertiesは.gitignore等に含めてVCSにはcommitしないようにしましょう。(local.propertiesだとbuild.gradleから見えなかったので今回はgradle.propertiesに書きました。何か良い方法あれば教えて下さい。)
gradle.properties
bintray_user=USER_NAME bintray_api_key=API_KEY
build.gradleに設定を書く
長いですがそんなに複雑でもないです。groupIdやversion、siteUrl等固有の値は変更しないといけないですが他はテンプレです。
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' } } apply plugin: 'com.android.library' android { //省略 } apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' group = 'com.sys1yagi.android' version = '1.0.0' def siteUrl = 'https://github.com/sys1yagi/toaster' def gitUrl = 'https://github.com/sys1yagi/toaster.git' bintray { user = bintray_user key = bintray_api_key configurations = ['archives'] //When uploading configuration files pkg { repo = 'maven' name = 'toaster' desc = 'Android Toaster! You can use toast anywhere.' websiteUrl = siteUrl issueTrackerUrl = 'https://github.com/sys1yagi/toaster/issues' vcsUrl = gitUrl licenses = ['Apache-2.0'] labels = ['android'] publicDownloadNumbers = true } } install { repositories.mavenInstaller { pom { project { packaging 'aar' name 'toaster' 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 'sys1yagi' name 'Toshihiro Yagi' email 'sylc.yagi@gmail.com' } } scm { connection 'https://github.com/sys1yagi/toaster.git' developerConnection 'https://github.com/sys1yagi/toaster.git' url siteUrl } } } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } 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 } task findConventions << { println project.getConvention() }
アップロードする
taskにbintrayUpload
が増えます。実行するとaarがBintrayのmaven repositoryにアップロードされます。
jcenterに登録する
↑のページの右下からjcenterへの登録を申請するフォームへ飛べます。申請が通ればbuildscriptの所でjcenter()
って書いてるプロジェクトならフツーにdependenciesでライブラリを追加出来るようになります。
試しにアップしたもの
toaster
というどうしようもないライブラリをアップしてみました。jcenterへのpublishは依頼中なのでまだbintrayのmaven repositoryを参照しないと使えません。今後はもっと有益なライブラリをアップできるよう善処します。