将自己的开源项目提交到JCenter
2015-03-10 16:27
190 查看
开始
最近自己写了一个开源控件,是有关标签流控件的(从服务器端获取标签,然后将标签自适应的放进一个容器里)。现在控件写完了,自己就想将它提交到Maven的中心仓库或者是JCenter。可是自己对maven不熟,并且用Android Studio写的工程提交到Maven的中心仓库确实比较繁琐,所以决定还是用JCenter。申请账号
关与项目提交到JCenter,网上有个教程写的很好,我基本上也是参照上面来做的,但是途中也遇到了一些坑,所以觉得还是有必要叙述一下的。首先你要做的是申请Bintray账号,它是JCenter的托管商,注册完成之后,你需要来到这个界面,记住你的账户名和API key,我一般将它放在local.properties文件中。因为我们待会会用到,做完这些后,你的第一步差不多即完成了。//local.properties sdk.dir=/Applications/ADT/sdk bintray.user = fyales bintray.apikey = *************************
配置工程的build.gradle文件和你要提交的Module的build.gradle文件
下面我们来看build.gradle文件:buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' 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() } }
这里我们用的仓库是JCenter而不是MavenCentral。并且我们需要引入官方提供的两个插件android-maven-plugin和gradle-bintrayl-plugin,这样便于我们提交项目到JCenter.
接下来就是配置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 } }
这串代码主要做了三件事
生成JavaDoc
生成Jar
配置我们项目的信息
在这里我要提醒一下,生成javadoc和jar是必选选项。一开始我认为做这些没有必要,所以没有写入生成javaDoc和jar的命令,于是,我收到了bintray的官方邮件(邮件中是另外一个项目):
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命令一开始运行失败,这是因为我喜欢在我的注释这样写
@author fyales @date
因为javadoc里面并没有@date ,所以会解析失败,大家也要注意一下。。。。。。。
做完这些后,就可以运行下面的命令将你的项目提交到Bintray了
./gradlew bintrayUpload
最后的步骤
提交完成之后,你就可以申请你的项目到JCenter,点击Include My Package,在弹出的界面输入你的项目名称确定就可以了,当审核通过后,你就可以直接用你自己项目了.dependencies { compile 'com.fyales.android:library:1.0.0' }
其他注意点
build失败(失败原因Cannot call getBootClasspath() before setTargetInfo() is called.)
解决方案:将gradle版本升级到1.2总结
JCenter相较于Maven Central还是很方便的,另外就是在软件开发过程中,有时候也要知其然,也要知其所以然。口号:Make things interesting!
参考
使用Gradle发布项目到JCenter仓库相关文章推荐
- 【编程初学者】创建自己的开源项目6-基于当前分支,提交归并请求到主分支(myeclipse+git)
- 将自己的开源项目提交到CocoaPods
- 【编程初学者】创建自己的开源项目4-将本地代码仓库的代码提交到远程代码仓库(myeclipse + github)
- 利用git向github上远程提交一个自己的开源项目
- 【编程初学者】创建自己的开源项目7-基于当前分支,提交归并请求到主分支2-代码冲突(myeclipse+git)
- 教大家如何一步一步的将自己的开源项目上传到jcenter
- git 怎么为开源项目做贡献,怎么有效管理贡献者的提交
- 开源自己的一个小android项目(美女撕衣服游戏)
- 开源项目SQLAlchemy对提交bug的回复
- 在金山卫士开源中如何开源自己的项目
- 最近想把自己的一些项目也开源
- 在Maven Central发布了自己的第一个开源项目
- [Github] 把自己做完的代码提交(commit以及push)到线上公共项目中
- 编写自己的ORM——LWNORM开源项目发布
- 关于目前自己iOS项目使用的第三方开源库
- 使用Gradle发布Android开源项目到JCenter
- [FAQ05995] 如何把自己的代码包或开源项目的code, 编译进android D
- 如何开源自己的项目
- 使用VS2008+SVN插件配合Google Code搭建自己的开源项目管理
- 建立自己的开源项目