Build JAR with a dependency from the custom repository

Viewed 74

I'm trying to build a JAR artifact which requires a custom dependency from the bintray repository, like:

    https://dl.bintray.com/foo/bar

Is it possible to instruct the project that consumes such a library that it should resolve dependencies in the extra repository?

Or should I take another approach to provide it?

1 Answers

TL;DR

Build a fat jar including your dependencies.

Long Version

Yes, it is potentially possible to instruct a project that consumes your Gradle plugin to download plugin dependencies from a non-default repository. But it requires the user intervention which is probably not what you want to hear.

The following settings.gradle should retrieve your plugin from the Gradle Plugin Portal and resolve the dependencies from your Bintray repository:

pluginManagement {
    repositories {
        maven {
            url 'https://dl.bintray.com/foo/bar'
        }

        gradlePluginPortal()
    }
}

This is documented under Plugin Management.

Please note that I'm a bit vague in my answer since I never did something similar. What I can tell is that the spring-cloud-contract plugin does exactly this for snapshot versions.

IMHO, in your specific case, you get the best user experience by building a fat jar that includes your dependencies. A remarkable companion being the Gradle Shadow Plugin. It also features additional functionality for Gradle plugins, should you ever need them.

Related