发布开源项目到 Bintray、Jcenter 遇到的坑

发布开源项目到 Bintray、Jcenter 遇到的坑

至于正常的发布流程,网上都有。

配置依赖:

project 的 build.gradle

dependencies {
    // 添加上传到jcenter所需的插件
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    classpath 'com.novoda:bintray-release:0.9.2' // 请使用最新版本
}

module 的 build.gradle

apply plugin: 'com.novoda.bintray-release'//添加

publish {
    userOrg = 'bugfreezrr' // bintray.com 该网站你的用户名
    groupId = 'com.bugfree.zhangruirui.vitas' // jcenter 上的路径
    artifactId = 'vitas'//项目名称
    publishVersion = '1.0.3'//版本号
    desc = 'vitas log'//描述,不重要
    website = 'https://github.com/selfconzrr' //网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了
}

执行命令

// (注意,windows系统,命令行前面不需要 ./) 
gradlew clean build bintrayUpload -PbintrayUser=**** -PbintrayKey=********** -PdryRun=false

需要注意的是每一个 - 前面都需要加上空格

  • -PbintrayUser=jcenter用户名
  • -PbintrayKey=apikey在自己的profile可以看到
  • -PdryRun=false 写false代表要上传

1、HTTP/1.1 404 Not Found [message: repo “maven” was not found]

repo.png

创建仓库很简单,但是:

  • Name 一定要填 maven,否则后面的发布操作是不成功的
  • Type也一定要选择 maven,表示是一个 maven 仓库
  • Licenses 是可选项,点击下拉的菜单可以选择 Apache-2.0

2、could not create package “”:HTTP/1.1 400 Bad Request [message: Please enter a valid VCS URL for your package]

上传时报该错,那是因为你没有创建 package,所以需要先创建 package 再进行上传。如下图,注意 package name 和 artifactid 必须一致,否则也会上传失败。
package.png

3、Execution failed for task ‘:xxxx:mavenAndroidJavadocs’. Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting):

注释采用中文,导致无法正常生成 Javadoc。生成 javadoc 报错,需要在你的工程的 build.gradle 文件中添加如下代码:

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
    // 下面三行
    tasks.withType(Javadoc) { // 新增
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}

4、Execution failed for task ‘:app:lint’. Lint found errors in the project

Lint 检查默认是开启的,Lint 会检查项目中的语法错误,如果没有通过则无法继续。只需要在 Module 的 build.gradle 添加如下代码

android {
    lintOptions {
        abortOnError false
    }
}

5、Execution failed for task ‘:vitas:bintrayUpload’.

org.apache.http.conn.HttpHostConnectException: Connection to https://api.bintray.com refused

网络问题导致的上传失败。尝试以下两种方式:

  • 关闭代理软件
  • 多试几次(orz:我就是多上传了几次,莫名其妙就成功了)

6、Execution failed for task ‘:vitas:bintrayUpload’. Could not upload to ‘https://api.bintray.com/content/bugfreezrr/maven/vitas/1.0.2/com/bugfree/zhangruirui/vitas/vitas/1.0.2/vitas-1.0.2-sources.jar’: HTTP/1.1 409 Conflict [message:Unable to upload files: An artifact with the path ‘com/bugfree/zhangruirui/vitas/vitas/1.0.2/vitas-1.0.2-sources.jar’ already exists]

如果你已经发布了 1.0.2 版本到 bintray,再次发布 1.0.2,就会报这个错误:

  • gradle 修改 publish.publishVersion
  • 或者在 bintray 删除当前版本,再重新发布

7、Bintray 上传包到 Jcenter 时,报错 “Failed to send a message: The version control 1.0.0 returns 404.”

jcenter.png

把这个 VCS 属性改成自己仓库的地址,可以是 GitHub 的地址

8、上传到仓库时报错:Execution failed for task ‘lib:bintrayUpload’. > java.net.ConnectException: Connection timed out: connect

原因:网络原因,当前使用的网络开了翻墙,导致连接失败
解决:换一个未翻墙的网络可以了

------至所有正在努力奋斗的程序猿们!加油!!
有码走遍天下 无码寸步难行
1024 - 梦想,永不止步!
爱编程 不爱Bug
爱加班 不爱黑眼圈
固执 但不偏执
疯狂 但不疯癫
生活里的菜鸟
工作中的大神
身怀宝藏,一心憧憬星辰大海
追求极致,目标始于高山之巅
一群怀揣好奇,梦想改变世界的孩子
一群追日逐浪,正在改变世界的极客
你们用最美的语言,诠释着科技的力量
你们用极速的创新,引领着时代的变迁

——乐于分享,共同进步,欢迎补充
——Treat Warnings As Errors
——Any comments greatly appreciated
——诚心欢迎各位交流讨论!QQ:1138517609
——CSDN:https://blog.csdn.net/u011489043
——简书:https://www.jianshu.com/u/4968682d58d1
——GitHub:https://github.com/selfconzrr

发布了79 篇原创文章 · 获赞 207 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/u011489043/article/details/96285374