👓 Gradle tutorial: Add a GitHub repo as dependency

I recently got the following Problem:

There were an API that needs to be implemented for a SpongePlugin and everytime I tried to build it, Gradle failed at ‘:compileJava’. I figured the problem had to be that the API I want to implement, wasn’t properly added through Gradle. The manual import was the problem.

So I figured i need to import the GitHub repo of this api-plugin with Gradle. After long research I got the following solution. Just add the following to your gradle.build-file after the plugin{...} section:

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

This adds the JitPack Plugin to Gradle with will help you to import any GitHub repo as dependency through this (just add the repo in the dependeny list like this):

dependencies {
    compile 'com.github.Username:Reponame:Tag

An example: compile 'com.github.Jano1:RegionsAPI:master-SNAPSHOT'
If there are no Tags set, you can use ‘branchname-SNAPSHOT’ to get the current state of the branch you want.
For further information about JitPack: JitPack.io

I hope I can spare some of you some time with this :smiley:

1 Like

Yeah, Jitpack is a godsend for those who are too lazy to publish to any public repository (like me :stuck_out_tongue:). IIRC PacketGate explicitly recommends it as its repository.

1 Like

Making a Bintray repo isn’t hard… Though jitpack is very nice for this stuff

And adding this to the API-repo allows you to have the source of it in the other repo.

Ok, thats a good thing! Until now I added them manuallly (it already felt wrong, but I knew no better way).

It’s the first time I work with Gradle, but I already like it :smile:
Now I’m angry I haven’t use it before in any project :smiley: