使用Gradle发布项目到JCenter仓库
2016-01-13 18:24
381 查看
如果想在AndroidStudio中直接使用别人的项目或者是库,一般的做法是在dependencies中进行compile,而compile的东西就是存放在JCenter或者Maven仓库中的。
在这里我上传到JCenter,因为现在默认是支持JCenter,同时JCenter也兼容Maven
1. 在根build.gradle中:
添加后两行classpath就可以了,第一行不用变
2. 在需要上传的Module下的build.gradle中:
第一行,如果是library就改为com.android.library。
后面两行必须的。
3. 在local.properties中:
API Key可以点击自己的头像,选择your profile->点击edit选项->选择API Key
这个文件一般是需要是.gitignore中写入的,避免信息泄露
默认.gitignore中是包含了它,如果没有,就需要手动加入
4. 生成
Rebuild一下,然后 ./gradlew install
5. 上传到Bintray
./gradlew bintrayUpload
上传完成即可在Bintray网站上找到你的Repo,我们需要完成最后一步工作,申请你的Repo添加到JCenter。可以进入这个页面,点击include my package, 输入你的项目名字点击匹配到的项目,然后写一写Comments再send即可,然后就等管理员批准了,我是大概等了40分钟,然后网站上会给你一条通过信息,然后就OK了,大功告成。
在这里我上传到JCenter,因为现在默认是支持JCenter,同时JCenter也兼容Maven
注册Bintray账号
简单注册就好,Bintray传送门, 也可以选择github或者其他方式登陆生成项目的JavaDoc和source JARs并上传
存放在JCenter仓库中的东西就是JavaDoc和sourceJARs.1. 在根build.gradle中:
添加后两行classpath就可以了,第一行不用变
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.0.0-alpha3' 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 } }
2. 在需要上传的Module下的build.gradle中:
第一行,如果是library就改为com.android.library。
后面两行必须的。
apply plugin: 'com.android.application' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' version = "1.0.0" android { compileSdkVersion 23 buildToolsVersion "23.0.2" resourcePrefix "" //随便填 defaultConfig { applicationId "com.customwidget.lzqwidget" minSdkVersion 14 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']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' } // 下面的可以全部复制,然后更改为自己的就好了 def siteUrl = 'https://github.com/LiZHongquan2013/CustomWidget' // 项目主页 def gitUrl = 'https://github.com/LiZHongquan2013/CustomWidget.git' // 项目git的clone地址 group = "com.customwidget.lzqwidget" // Maven Group ID for the artifact 一般为包名 install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' // Add your description here name 'Android CustomWidget' //项目描述 url siteUrl // Set your license, 不用修改 licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'LiZHongquan2013' name 'LiZHongquan2013' email 'JonsTank2013@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 = "CustomWidget" websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
3. 在local.properties中:
API Key可以点击自己的头像,选择your profile->点击edit选项->选择API Key
bintray.user=填写你的Bintray用户名 bintray.apikey=填写你的Bintray API Key
这个文件一般是需要是.gitignore中写入的,避免信息泄露
默认.gitignore中是包含了它,如果没有,就需要手动加入
4. 生成
Rebuild一下,然后 ./gradlew install
5. 上传到Bintray
./gradlew bintrayUpload
上传完成即可在Bintray网站上找到你的Repo,我们需要完成最后一步工作,申请你的Repo添加到JCenter。可以进入这个页面,点击include my package, 输入你的项目名字点击匹配到的项目,然后写一写Comments再send即可,然后就等管理员批准了,我是大概等了40分钟,然后网站上会给你一条通过信息,然后就OK了,大功告成。
相关文章推荐
- IOS中延时执行的几种方式的比较和汇总
- switch case 没有break 和default 位置乱放分析
- centos 7 subversion
- mysql常用命令
- jmeter beanshell内容
- memcached的最佳实践方案
- 安装DirectX SDK提示Error Code: S1023
- Maven error “Failure to transfer…wan cached in local repository”
- Loadrunner 出错退出
- 文章标题
- listen()的backlog参数和未完成队列、已完成队列的关系
- Java 继承
- Culling的一些介绍
- 2015 Python News
- GCD的常用方法
- redis配置文件详解
- Mybatis异常-SQL执行没反应,但oracle单独执行正常
- AFNetworking 3.0迁移指南 及基本使用方法
- java反射机制之Method invoke执行调用方法例子
- iOS小demo之图片变灰