發布開源庫到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刪除,重新運行上傳命令即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM