A few days ago I have fight for adding a Jitpack source to my Android project. While I am a year long Android developer that sounds very funny. But my requirements were the issue. I wanted to get a Gradle plugin from Github via Jitpack. This should configured over the Gradle version catalog.

While this is my first project where I using the Gradle version catalog this was a very hard try-and-error. But finally the task is solved. And I want to share my new learning with you!

Wrong repository?

Let us use this Lokalise plugin as example. Public plugins are often available at Gradle’s plugin portal. A simple plugin(...) is enough to get your plugin installed.

./settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal() // Gradle's plugin portal
        // ...
    }
}

dependencyResolutionManagement {
    // ...

    versionCatalogs {
        plugin('lokalise', 'com.ioki.lokalise').version('1.0.0')
    }
}

If you try to sync your project, you will get the following error.

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (None of the included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'com.ioki.lokalise:com.ioki.lokalise.gradle.plugin:1.0.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo

The first intention is to add Jitpack to plugin managment repositories. Nice try! But you will get the same error.

# ...
- Plugin Repositories (could not resolve plugin artifact 'com.ioki.lokalise:com.ioki.lokalise.gradle.plugin:1.0.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo
    maven(https://jitpack.io)

Overwriting package resolution

The mentioned artifact show us, that the plugin needs to use his name for group com.ioki.lokalise and name (com.ioki.lokalise) plus .gradle.plugin as module name. Everyone who uses Jitpack before known that the package should be com.github.ioki. But we can’t use com.github.ioki-mobility:LokaliseGradlePlugin on our version catalog. Only package names (no artifact patterns) allowed for plugins.

To resolve this issue we need to overwrite the resolution of our plugin. It is possible to intercept the plugin package request.

./settings.gradle

pluginManagement {
    // ...

    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'com.ioki.lokalise') {
                useModule('com.github.ioki-mobility:LokaliseGradlePlugin:36bbf54fe0')
            }
        }
    }
}

Use resolutionStrategy to intercept every plugin request. To overwrite the right package your need compare requested.id.id to your plugin name. With useModule(...) you can set the familiar package pattern. Now the correct package is fetched and your plugin definition on version catalog will work.

Finally you will have the following code snippet to get your plugin.

./settings.gradle

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

    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'com.ioki.lokalise') {
                useModule('com.github.ioki-mobility:LokaliseGradlePlugin:36bbf54fe0')
            }
        }
    }
}

dependencyResolutionManagement {
    // ...

    versionCatalogs {
        plugin('lokalise', 'com.ioki.lokalise').version('1.0.0')
    }
}

I hope this will help you to get fix your issue soon!