发布开源库到Jcenter和Maven Central

前言:

在开发中,经常会使用第三方库,一般是通过maven或gradle的方式引用。很方便,整个引用过程也就几行配置代码(gradle只用一行)。

下面就是记录将将自己的的库开源出去的整个流程:

参照https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en 【翻译在此】
这里已经很详细了,接下来是实际操作过程中应注意的地方:

1、在Mac终端中,gradle的相关命令应 ./gradlew xxx这样写,以下都默认在Mac中

2、在运行./gradew install时,会报

Caused by: java.lang.NoClassDefFoundError: org/gradle/api/publication/maven/internal/DefaultMavenFactory

当使用的Gradle版本是2.4以上,Android插件版本是1.3.0以上的时候就会出现这个问题,这时候我们需在project的 build.gradle 文件中的插件版本添加一行
classpath ‘com.github.dcendents:android-maven-gradle-plugin:1.3’

3、在运行./gradlew bintrayUpload时,报

What went wrong:
Execution failed for task ':library:bintrayUpload'.
Could not create package 'sujian27@163.com/maven/simplify': HTTP/1.1 401 Unauthorized [message:This resource requires authentication]

这是local.properites中的bintray.user配置错误导致的。在注册bintray时,直接用github的账号注册的,这时候bintray.user应为主页显示的那个名称,而不是邮箱。

4、在运行./gradlew bintrayUpload时,报

What went wrong:
Execution failed for task ':library:bintrayUpload'.
Could not upload to 'https://api.bintray.com/content/timesfire/maven/simplify/0.1.0/com/github/timesfire/library/0.1.0/library-0.1.0.pom': HTTP/1.1 400 Bad Request [message:Unable to upload files: Maven group, artifact or version defined in the pom file do not match the file path 'com/github/timesfire/library/0.1.0/library-0.1.0.pom']

这个时候我们的库已经上传到bintray上了,在对应的maven目录下也有对应的tag生成,但是不能正常引用,这是因为需要上传的库工程对应的module名称和我们配置的不一致,默认的库module名称是library,只需重命名为我们配置的名称即可,我这里是重命名为simplify。让后先将bintray上已经生成的TAG删除,重新运行上传命令即可。

posted @ 2016-07-04 15:05  摇曳清风  阅读(2602)  评论(0编辑  收藏  举报