Gradle - Reusing buildscript Repositories

Gradle is a leading build tool. It downloads libraries from the declared repositories. It has a flaw that you have to declare repositories twice (buildscript.repositories and repositories) if you are using plugins.

Especially in an enterprise, It is cumbersome to deal as the definition of a repository can be more than a single line or there could be multiple repositories (public/private).

Avoid doing work twice; Define Repository Once and use it all over.

buildscript {
  repositories {
    maven {
      // Define name of repository
      name 'myRepository1'
      url ''
      metadataSources: {
      credentials {
        username "user"
        password "password"

Selective Repository

// this line is going to save the effort

All Repository

repositories = buildscript.repositories

Be Updated

Only articles are shared on Medium

This site uses third-party cookies to gather website usage and performance data.