Add DefaultRepositoryHandler for Gradle Plugins - https://plugins.gradle.org/m2/

Can we please add a method for maven { url 'https://plugins.gradle.org/m2/' }? We have one for mavenCentral() and jcenter().

It is a few lines of code to add here: https://github.com/gradle/gradle/blob/f490bdf61bd9b4f5383cd9fb0d8ffbca93da8c32/subprojects/core/src/main/groovy/org/gradle/api/internal/artifacts/dsl/DefaultRepositoryHandler.java#L71.

Something like:

public static final String DEFAULT_GRADLE_REPO_NAME = "GradlePlugins";
public static final String GRADLE_URL = "https://plugins.gradle.org/m2/";

public MavenArtifactRepository gradleRepo() {
        return addRepository(repositoryFactory.createGradleRepository(), DEFAULT_GRADLE_REPO_NAME);
}

public MavenArtifactRepository gradleRepo(Action<? super MavenArtifactRepository> action) {
        return addRepository(repositoryFactory.createGradleRepository(), DEFAULT_GRADLE_REPO_NAME, action);
}

Once this issue is acknowledged, I can make a quick pull request to the Gradle github.

Hi @jaredsburrows,

It’s an interesting request. Can you help me understand your use case? (i.e. Why do you want to supply the Gradle Plugins Portal repo as a repository in your build script?

One of the nice things about the Gradle Plugin Portal is that you don’t need to set up a reference to its maven repository to use the plugins from there. You simply use the plugins block and provide the id and version of the plugin you want to use. The Gradle Plugin Portal then figures out what maven artifacts you need to provide that plugin from the repo.

Example

plugins {
    id "com.jfrog.bintray" version "0.4.1"
}

If you still want a gradleRepo() method like the one you are suggesting, I think we need to establish a better understanding for why.

Thanks,
Pepper

I have one: When preparing course materials which involve Gradle, I like to have the ability to cache everything in a local repository (using the Ivypot plugin). In those cases I need to specify the plugin repository in order to download the plugins as well. It would just be nice to have it as a named repo available both in buildscript.repositories and in project.repositories.

One usecase I see for this is when you have a gradle plugin project that extends other plugins that are hosted by the plugin portal.

2 Likes

@eljobe

There are two things:

  • Using the newer gradle plugins block like you suggested:
plugins {
    id "com.jfrog.bintray" version "0.4.1"
}

Only works with plugins that hosted on Gradle.

  • In most builds you see the following:
repositories {
     jcenter()
     mavenCentral()
}

I simply want to reduce this to something like:

repositories {
    gradleRepo() // maven { url 'https://plugins.gradle.org/m2/' }
}

Since the official gradle repo mirrors both Jcenter and MavenCentral, the use case is really nice, simple and clean.

For my local “debug” builds, I usually have the following:

repositories {
    maven { url 'https://plugins.gradle.org/m2/' } // Mirrors jcenter() and mavenCentral()
    mavenLocal() // Local built libs
}

Since I use the gradle repo most of the time, it would be nice to have a method for it. :slight_smile:

@eljobe
Could I make a PR for this?

Sorry to drop the ball on this conversation. Yes, go ahead and make the Pull Request. I think there is sufficient interest in this.

1 Like

I have a PR for it here: https://github.com/gradle/gradle/pull/613.