# Suggestion regarding "repositories" documentation

**URL:** <https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585>\
**Category:** Bugs\
**Created:** [February 18, 2016, 9:33am UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585 "2016-02-18T09:33:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![huxi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/huxi/32/124_2.png) [@huxi](https://discuss.gradle.org/u/huxi)\
**Post date:** [February 18, 2016, 9:33am UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585/1 "2016-02-18T09:33:00Z")

</div>

[RepositoryHandler DSL Reference](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html) and [23.6. Repositories](https://docs.gradle.org/current/userguide/dependency_management.html#sec: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:

```gradle
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.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [February 18, 2016, 6:34pm UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585/2 "2016-02-18T18:34:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![huxi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/huxi/32/124_2.png) [@huxi](https://discuss.gradle.org/u/huxi)\
**Post date:** [February 19, 2016, 1:06am UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585/3 "2016-02-19T01:06:34Z")

</div>

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. 🙂

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:

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

allprojects {
    repositories {
        addAll buildscript.repositories
    }
}

```

Am I wrong with my assumption?

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [February 22, 2016, 12:53am UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585/4 "2016-02-22T00:53:05Z")

</div>

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 🙂 ), then having this in the JavaDoc is good enough.

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [February 22, 2016, 11:43am UTC](https://discuss.gradle.org/t/suggestion-regarding-repositories-documentation/14585/5 "2016-02-22T11:43:27Z")

</div>

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