简体   繁体   English

使用github上托管的个人库作为gradle依赖

[英]Using personal library hosted on github as gradle dependency

I have an android library that is hosted on github and need to add it as a dependency to another project without manually cloning the repository and adding it as a module dependency. 我有一个托管在github上的android库,需要将它作为依赖项添加到另一个项目,而无需手动克隆存储库并将其添加为模块依赖项。 How do I go about creating my own gradle dependency with link from github? 如何使用github中的链接创建自己的gradle依赖? Thanks! 谢谢!

If you've pushed your code to GitHub then sharing your library is easy with JitPack . 如果您已将代码推送到GitHub,那么使用JitPack可以轻松共享您的库。

Your users will just need to add the repository to their build.gradle: 您的用户只需要将存储库添加到他们的build.gradle:

repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}

and then your GitHub repository as dependency: 然后你的GitHub存储库作为依赖:

dependencies {
    compile 'com.github.YourUsername:Repo:Release'
}

JitPack acts as a maven repository and can be used like Maven Central. JitPack充当maven存储库,可以像Maven Central一样使用。 The nice thing is that you don't have to upload your library. 好消息是你不必上传你的图书馆。 Behind the scenes JitPack will check out the code from GitHub and compile it. 在幕后,JitPack将检查GitHub中的代码并进行编译。 As you publish a new release on GitHub it becomes available for others to use. 当您在GitHub上发布新版本时,其他人可以使用它。

There is also a guide on how to prepare an Android project. 还有一个关于如何准备Android项目的指南。

Github is not a maven repository. Github不是maven存储库。 if it's "free for all" license, you can clone project and post it for example in jCenter , then add it as gradle dependency. 如果它是“free for all”许可证,您可以克隆项目并将其发布到例如jCenter中 ,然后将其添加为gradle依赖项。

You have to release your library to a repository which can be used by Gradle. 您必须将库发布到可由Gradle使用的存储库。 When you want the library to be publicly available you can publish it to Maven Central. 如果希望库公开,可以将其发布到Maven Central。 See http://central.sonatype.org/pages/gradle.html#releasing-the-deployment-to-the-central-repository for details about how to publish your library from gradle to Maven Central. 有关如何将库从gradle发布到Maven Central的详细信息,请参见http://central.sonatype.org/pages/gradle.html#releasing-the-deployment-to-the-central-repository

Once published in Maven Central use the normal gradle dependency declaration. 一旦在Maven Central中发布,就使用普通的gradle依赖声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM