Using JitPack to Install Gradle Plugins from Git Sources

Featured image for sharing metadata for article

Today, I was trying to release the Jenkins Job DSL plugin when I found that I needed to upgrade a couple of plugins to resolve an issue with a Gradle upgrade.

As mentioned in upstream issues for the affected plugins, the fix had been made on the primary branch but the plugin had not yet been released.

One option, as mentioned by folks on the issues, is to publish them yourself or vendor them into the project, which can be messy and frustrating.

An alternative is something I found super useful when working with the Spotless project, called out in their contributing docs, which is the JitPack service.

JitPack is a service that makes it possible to build JVM libraries from a number of Git hosting tools. This allows us to point Gradle to the JitPack repository for specific dependencies, where JitPack will build an artefact for us for the given Git commit and publish it so we can consume it.

Let's say that your build.gradle currently looks like this:

plugins {
  // in my opinion, removing `version` makes it more obvious that we're using JitPack, but it can stay too
  id 'com.eriwen.gradle.css' version '2.14.0'
  id 'com.eriwen.gradle.js' version '2.14.1'
}

In our settings.gradle, we need to add the Maven repository for JitPack, and then specify a resolutionStrategy for each of the plugins that we want to pull, ensuring that we specify a version that is either a Git SHA for the commit we want to build, or specify a branch name:

pluginManagement {
  repositories {
    gradlePluginPortal()
      maven {
        url 'https://jitpack.io'
      }
  }
  resolutionStrategy {
    eachPlugin {
      if (requested.id.id == 'com.eriwen.gradle.css') {
        useModule('com.github.eriwen:gradle-css-plugin:9fe88d7') // can also be a branch, i.e. `master-SNAPSHOT`
      }
      if (requested.id.id == 'com.eriwen.gradle.js') {
        useModule('com.github.eriwen:gradle-js-plugin:d15f4ae') // can also be a branch, i.e. `master-SNAPSHOT`
      }
    }
  }
}

And just like that, you don't need to worry (as much) about plugins not yet being released!

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #gradle #java #jitpack.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.