Repositories

RepositoryHandler is documented here, which is represented by "repositories" script

A RepositoryHandler manages a set of repositories, allowing repositories to be defined and queried.


flatdir //a set of local directories
google() //google maven repo
gradlePluginPortal() //gradles repos
ivy
Jcenter
maven
mavenCentral
mavenLocal

repositories {
    mavenCentral artifactUrls: 
             ["http://www.mycompany.com/artifacts1", 
               "http://www.mycompany.com/artifacts2"]

    mavenCentral name: "nonDefaultName", 
        artifactUrls: ["http://www.mycompany.com/artifacts1"]
}

repositories {
    mavenCentral()
}

repositories {
  jcenter {
    artifactUrls = 
       ["http://www.mycompany.com/artifacts1",
        "http://www.mycompany.com/artifacts2"]
  }
  jcenter {
    name = "nonDefaultName"
    artifactUrls = ["http://www.mycompany.com/artifacts1"]
  }
}

repositories {
    flatDir name: 'libs', dirs: "$projectDir/libs"
    flatDir dirs: ["$projectDir/libs1", "$projectDir/libs2"]
}

JCenter and Maven uses the following object to configure themselves


repositories {
  //This creates a repo pointing to the maven central
  mavenCentral()

  //This creates another maven repo
  //Sets its URL
  maven {
     url "some-url"
     //The following simply overwrites the one before
     //So one is enough
     setUrl("some-other-url");
  }

  //This creates a third maven repo
  //if you want at a different url
  maven {
     url "some-new-url"
  }

}//end of repos

So each entry under repositories creates a new repository

More than one repository of a particular type is ok

Go to the repos doc page above at Gradle and see what Java object is represented by that particular repo. Java API will tell you how to configure that particular repo.

For example here is the MavenRepo java object: MavenArtifactRepository


buildscript {

       ext {
              var1 = 'value1'
       }

       repositories {
        maven {
            println "\nOutput from first maven"
            println "***********************"
            println it
            println delegate
            println owner

            println this
            //The following is wrong, the last will take affect
              url ?url1'
              setUrl('url2')
        }

        //you can do this instead
        maven {
            println "\nOutput from second maven"
            println "***********************"

              println it
              println delegate
              println owner
              println this
              url = "blah again" // :)

        }
       }
}

 

task Target {
       doLast {
              println "done"
              println it
              println delegate
       }
}

> Configure project :

Output from first maven

***********************

org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_De

corated@c4664c

org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_De

corated@c4664c

DynamicObject for org.gradle.api.internal.artifacts.repositories.DefaultMavenArt

ifactRepository_Decorated@c4664c

root project 'Sample 3, Test Property Scope'

Output from second maven

***********************

org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_De

corated@12a713e

org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_De

corated@12a713e

DynamicObject for org.gradle.api.internal.artifacts.repositories.DefaultMavenArt

ifactRepository_Decorated@12a713e

root project 'Sample 3, Test Property Scope'

> Task :Target

done

task ':Target'

task ':Target'


//A method call on Project
//Delegate is the RepositoryHandler
//(You know that by looking at Project Signature)

repositories {

   //A method call on RepositoryHandler
   //Creates a Repo represented by
   //MavenArtifactRepository
   Jcenter()

   Jcenter {
     //MavenArtifactRepository
     //is avaiale as the delegate
     //of this closure
     //So all methods are fair game
     //on that delegated object
   }
}

the method setUrl(url) is not a plural. It only allows 1 URL per repo. This is perhaps to allow for multiple credentials and other assets of that repo.