Published on

How to use JitPack

Authors

Today I was trying to make a minor change to a project but ran into an issue with the one dependency I was using, basically I was getting a not found on a non-Maven central repository.

I could not find a newer version or an alternative hosting provider but luckily JitPack can help you overcome this as long as the dependency you need is a public git repo.

The steps below demonstrate how to do this:

Add JitPack to the end of your repositories section in your build.gradle file:

repositories {
  mavenCentral()
  //
  maven { url 'https://jitpack.io' }
}

The ordering is important as Gradle will look for dependencies in the repos top down, it will only try the next repo in the repositories list if it cannot find it in the one further up. JitPack would only need to be hit for a few dependencies further down instead of most dependencies so it is better left at the bottom otherwise it could slow your build down as it will not be able to find most deps and only after trying and missing it will then try the next repository in your list.

Update the Dependency You Need to use JitPack

Lets use a common repo as an example to show how we do this.

Say we want to do this for apache/commons-lang

We would need the following:

  1. Repo username: in our case this is the part after github.com so apache
  2. The repo name itself: commons-lang
  3. The git tag we want: we will use commons-lang-3.12.0-RC1 but if there is no tag you can also use a branch name for example master

Now to import the above using JitPack add the following to your build.gradle's dependencies section:

dependencies {
    //...
    implementation 'com.github.apache:commons-lang:rel~commons-lang-3.12.0'
    //...
  }

The scheme as per JitPack is: implementation 'com.github.[User]:[Repo]:[Tag]'