Suggestion regarding "repositories" documentation

RepositoryHandler DSL Reference and 23.6. Repositories should mention the addAll method of RepositoryHandler and provide some usage examples.

I just realized that it’s possible to write something like this:

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}

allprojects {
    repositories {
        addAll buildscript.repositories
    }
}

I previously duplicated the repositories blocks which bothered me quite a bit, but not enough to take a closer look at the API than the documentation links above. I would have really appreciated a blurb like the one above.

I would not encourage people to do that too much. Every repository you add adds to dependency resolution time. The snippet you posted would add the Gradle Plugin Portal as a repository for project dependencies, which is almost definitely not needed.

Granted, the snippet above is a bit more absurd than it should be… That’s because I removed our local nexus repository/cache from the top of the list while copy-pasting it. :slightly_smiling:

It is my understanding that searching stops once a dependency has been found in one of the configured repositories. I think I even saw a bug report complaining about this in case of SNAPSHOT versions but it feels like a feature to me.

So the above example should rather look like this:

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
}

allprojects {
    repositories {
        addAll buildscript.repositories
    }
}

Am I wrong with my assumption?

Yes, Gradle will search the repositories in order. But you still want it to find the dependency as fast as possible or fail as fast as possible if it can’t be found. So for the buildscript block you want the Gradle Plugin Portal to be at the top, not the bottom. For the main project dependencies you don’t want it at all. These two usages have quite different requirements.

I think if you know what you are doing (and you do :slight_smile: ), then having this in the JavaDoc is good enough.

and keep in mind that for dynamic versioned dependencies always all repositories are inspected.