How to use your forked version of plugin in Gradle

391 Views Asked by At

I'm using gradle plugin as

plugins {
    id 'net.ltgt.errorprone' version '2.0.2' apply false
}

Now, I forked net.ltgt.errorprone on Github, did some changes in branch changes. How can I tell Gradle to use the fork instead of upstream?

I've found this 'Fork' git repository as dependency in gradle for dependencies, looking for something similar for plugins.

1

There are 1 best solutions below

0
On

I solved it using jitpack.io to distribute the forked code into my app as a dep.

You can go to https://jitpack.io/ and enter your git url, it will give you available refs to use.

jitpack refs

Also, don't forget to check ref's log so you know jitpack can actually build your dep.

The log is available via icon in Log column.
If the icon is not visible, you can access it via url.
E.g. for commit hash 384433165eba475b113189d05786d4daf17c465c it is located on https://jitpack.io/com/github/johnrengelman/shadow/384433165eba475b113189d05786d4daf17c465c/build.log
There you can see the build is actually broken as the plugins needs at least jdk 11 but jitpack runs it with v1.8.

You can force jitpack tu use another jdk version by creating jitpack.yml in project's root with following content:

jdk: openjdk11

See https://jitpack.io/docs/BUILDING/#java-version for more info.

I've found few ways how to use the fork but I liked this one the most:

Let's say you use these

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'
}

So you can replace them with your fork via adding this (jitpack repository and replacement resolution) to your settings.gradle:

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`
      }
    }
  }
}