[Plugin Publish] How to declare a maven repository url for user's classpath resolution

In my gradle plugin project, I added a maven repository from jitpack.

// From a gradle plugin project
buildscript {
    repositories {
        mavenCentral()
        maven {
            url = uri("https://www.jitpack.io")
        }
    }
}

And I added some dependencies from GitHub projects which don’t publish to MavenCentral.
Also, I used shadowJar to copy all dependencies into my archive jar, for plugin publishing. By the way, I don’t know whether it’s necessary.


However, when I apply this plugin in another project, it said:

// From a production project
A problem occurred configuring root project 'DST'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.github.anuken.arc:arc-core:123fbf12b9.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/com/github/anuken/arc/arc-core/123fbf12b9/arc-core-123fbf12b9.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project : > io.github.liplum.mgpp:io.github.liplum.mgpp.gradle.plugin:1.0.2 > io.github.liplum.mgpp:MindustryGradlePluginPlumy:1.0.2

When I added maven repository from jitpack, it’s solved.

// From a production project
buildscript {
    repositories {
        maven {
            url "https://www.jitpack.io"
        }
    }
}

So, my question is:
How can I declare what 3rd party maven repository I used in plugin project, in order users don’t have to import it in their buildscript manually.


My plugin’s repo is here: GitHub - PlumyGame/mgpp: A Mindustry gradle plugin, named Plumy., hopefuly it can help you solve this problem.

If you pack the dependencies into your plugin jar (you should probably then also relocate them, so that there is no conflict with other jars on the build script class path) you should also make sure the dependencies don’t make it into the published metadata. (I don’t know how, as I dislike fast jars, especially for published jars).

If you do not publish a fat jar, but the normal jar with published dependencies, then you cannot automatically have the repositories. That would also be fatal, as for example many corporate users must not use other repositories but internal corporate ones. The user is responsible to provide the repositories in which the dependencies can be found. The proper way is to add to your documentation which repositories are needed and maybe even which dependencies from them.

Thank for your solution.
And the solution I currently worked out is a fat jar. :joy:

dependencies {
    compileOnly("com.github.anuken.arc:arc-core:$arcVersion")
    testImplementation("com.github.anuken.arc:arc-core:$arcVersion")
}
tasks.named<Jar>("jar") {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from(
        configurations.compileClasspath.get().mapNotNull {
            if (it.isFile && it.extension == "jar" && "arc-core" in it.name) zipTree(it)
            else null
        }
    )
}

Thanks to compileOnly, the 3rd party library isn’t involved in publihsed metadata, so that the users don’t have to declare the jitpack as a maven repositry if they can’t even use jitpack.