账户配置
首选需要拥有一个bintray的账号,还有与之对应的API key 可以直接使用github账号登陆.
登陆完成之后编辑页面下方列表中找到API key点击,得到自己的API key,保存下来就可以继续下一步.
在引用项目的时候,通常都是如下结构compile 'com.android.support:appcompat-v7:23.2.0'
结构分为三块,中间用:
来进行隔开,示例:group:name:version
项目根部路配置
回到项目中来,首先需要在根目录的build.gradle加入如下配置.
最后在加入两个帮助发布项目的插件,加载哪就不多说了,详细信息可以看项目github,maven 1.3插件需要gradle 2.4+支持,需要注意
上传的Module配置
然后去到需要上传的module中,开始在该module的build.gradle进行配置
添加插件
123// 在根节点上添加apply plugin: 'com.github.dcendents.android-maven'apply plugin: 'com.jfrog.bintray'定义相关网站
123// 这里就是直接引用根目录下的相关配置def siteUrl = "https://github.com/ErQi/${rootProject.ext.artifactName}"def gitUrl = "https://github.com/ErQi/${rootProject.ext.artifactName}.git"定义pom并打包aar
上传到jcenter至少需要四个文件,除了打包的aar之外,还需要pom和javadoc,source,否则是通不过jcenter审核的。不过不用紧张,这些我们都可以用脚本生成。
123456789101112131415161718192021222324252627282930313233// 根节点添加install {repositories.mavenInstaller {// This generates POM.xml with proper parameterspom {project {packaging 'aar'// Add your description herename rootProject.ext.artifactNameurl siteUrl// Set your licenselicenses {license {name 'The MIT License (MIT)'url 'http://opensource.org/licenses/MIT'}}developers {developer {id 'ErQi'name 'ErQi'email 'shengguangchanhui@foxmail.com'}}scm {connection gitUrldeveloperConnection gitUrlurl siteUrl}}}}}打包javadocjar和sourcejar
这是上传到jcenter必须的.
123456789101112131415161718// 根节点下task sourcesJar(type: Jar) {from android.sourceSets.main.java.srcDirsclassifier = 'sources'}task javadoc(type: Javadoc) {source = android.sourceSets.main.java.srcDirsclasspath += project.files(android.getBootClasspath().join(File.pathSeparator))options.encoding = 'UTF-8'}task javadocJar(type: Jar, dependsOn: javadoc) {classifier = 'javadoc'from javadoc.destinationDir}artifacts {archives javadocJararchives sourcesJar}配置Jcenter相关信息
12345678910111213141516171819202122232425262728Properties properties = new Properties()File propertyFile = project.rootProject.file('local.properties') // 这里将Jcenter的用户信息保存在local.properties文件中properties.load(propertyFile.newDataInputStream())bintray {user = properties.getProperty("bintray.user") //你的Jcenter账户key = properties.getProperty("bintray.apikey") //你的Jcenter账户的API keyconfigurations = ['archives'] //When uploading Maven-based publication filesdryRun = false //Whether to run this as dry-run, without deployingpublish = true //If version should be auto published after an uploadpkg {repo= 'maven' //发布到那个仓库name = rootProject.ext.artifactName // 库的名称desc = rootProject.ext.artifactDescription // 描述websiteUrl = siteUrl // 项目网址, 通常指向github链接issueTrackerUrl = siteUrl + '/issues' // 同上vcsUrl = gitUrl // 同上licenses = ['MIT']labels = rootProject.ext.artifactLabelspublicDownloadNumbers = true//Optional version descriptorversion {name = rootProject.ext.releaseVersionName //Bintray logical version namereleased = new SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss.SSSZZ').format(new Date())//2 possible values: date in the format of 'yyyy-MM-dd'T'HH:mm:ss.SSSZZ' OR a java.util.Date instancevcsTag = rootProject.ext.releaseVersionName}}}运行上传指令
当以上配置完成时,就可以运行gradle指令了
当两个任务都OK时,就可以登录自己的账户去提交审核了
在bintray的个人主页可以在右下角看到最近提交的记录,点击项目名称,即可进入到项目界面.
然后在主页的右下方找到Add to JCenter,然后在暂开网页中随便填一点描述信息,即可提交审核,当审核完成就可以使用了简单的一行直接导入了.12gradle installgradle bintrayUpload可能出现的坑
第一个指令用于生成pom.jar包,生成时会检测对应的方法注释,请确保注释完成无误.
第二个指令用于上传到指定的Jcenter账户,请确认账户的信息是否输入完成,例如该项目的user
,apikey
,可将此信息放置于其他文件中,此处保存在了local.properties
文件中,上传时若出现user apikey等错误信息,请确认账户信息是否有误.123456Properties properties = new Properties()File propertyFile = project.rootProject.file('local.properties') // 这里将Jcenter的用户信息保存在local.properties文件中properties.load(propertyFile.newDataInputStream())bintray {user = properties.getProperty("bintray.user") //你的Jcenter账户key = properties.getProperty("bintray.apikey") //你的Jcenter账户的API key