// tag::maven-ivy-repository-no-auth[]
repositories {
    maven {
        url "http://repo.mycompany.com/maven2"
    }

    ivy {
        url "http://repo.mycompany.com/repo"
    }
}
// end::maven-ivy-repository-no-auth[]

// tag::maven-ivy-repository-auth[]
repositories {
    maven {
        url "sftp://repo.mycompany.com:22/maven2"
        credentials {
            username "user"
            password "password"
        }
    }

    ivy {
        url "sftp://repo.mycompany.com:22/repo"
        credentials {
            username "user"
            password "password"
        }
    }
}
// end::maven-ivy-repository-auth[]

// tag::maven-ivy-s3-repository[]
repositories {
    maven {
        url "s3://myCompanyBucket/maven2"
        credentials(AwsCredentials) {
            accessKey "someKey"
            secretKey "someSecret"
            // optional
            sessionToken "someSTSToken"
        }
    }

    ivy {
        url "s3://myCompanyBucket/ivyrepo"
        credentials(AwsCredentials) {
            accessKey "someKey"
            secretKey "someSecret"
            // optional
            sessionToken "someSTSToken"
        }
    }
}
// end::maven-ivy-s3-repository[]

// tag::maven-ivy-s3-repository-with-iam[]
repositories {
    maven {
        url "s3://myCompanyBucket/maven2"
        authentication {
           awsIm(AwsImAuthentication) // load from EC2 role or env var
        }
    }

    ivy {
        url "s3://myCompanyBucket/ivyrepo"
        authentication {
           awsIm(AwsImAuthentication)
        }
    }
}
// end::maven-ivy-s3-repository-with-iam[]

// tag::maven-ivy-gcs-repository[]
repositories {
    maven {
        url "gcs://myCompanyBucket/maven2"
    }

    ivy {
        url "gcs://myCompanyBucket/ivyrepo"
    }
}
// end::maven-ivy-gcs-repository[]

// tag::maven-central[]
repositories {
    mavenCentral()
}
// end::maven-central[]

// tag::maven-jcenter[]
repositories {
    jcenter()
}
// end::maven-jcenter[]

// tag::maven-google[]
repositories {
    google()
}
// end::maven-google[]

// tag::maven-local[]
repositories {
    mavenLocal()
}
// end::maven-local[]

// tag::maven-like-repo[]
repositories {
    maven {
        url "http://repo.mycompany.com/maven2"
    }
}
// end::maven-like-repo[]

// tag::maven-like-repo-with-jar-repo[]
repositories {
    maven {
        // Look for POMs and artifacts, such as JARs, here
        url "http://repo2.mycompany.com/maven2"
        // Look for artifacts here if not found at the above location
        artifactUrls "http://repo.mycompany.com/jars"
        artifactUrls "http://repo.mycompany.com/jars2"
    }
}
// end::maven-like-repo-with-jar-repo[]

// tag::authenticated-maven-repo[]
repositories {
    maven {
        url "http://repo.mycompany.com/maven2"
        credentials {
            username "user"
            password "password"
        }
    }
}
// end::authenticated-maven-repo[]

// tag::header-authenticated-maven-repo[]
repositories {
    maven {
        url "http://repo.mycompany.com/maven2"
        credentials(HttpHeaderCredentials) {
            name = "Private-Token"
            value = "TOKEN"
        }
        authentication {
            header(HttpHeaderAuthentication)
        }
    }
}
// end::header-authenticated-maven-repo[]

// tag::flat-dir[]
// tag::flat-dir-multi[]
repositories {
    flatDir {
        dirs 'lib'
    }
// end::flat-dir[]
    flatDir {
        dirs 'lib1', 'lib2'
    }
// tag::flat-dir[]
}
// end::flat-dir[]
// end::flat-dir-multi[]

// tag::ivy-repo[]
repositories {
    ivy {
        url "http://repo.mycompany.com/repo"
    }
}
// end::ivy-repo[]

// tag::local-ivy-repo[]
repositories {
    ivy {
        // URL can refer to a local directory
        url "../local-repo"
    }
}
// end::local-ivy-repo[]

// tag::ivy-repo-with-maven-layout[]
repositories {
    ivy {
        url "http://repo.mycompany.com/repo"
        layout "maven"
    }
}
// end::ivy-repo-with-maven-layout[]

// tag::ivy-repo-with-pattern-layout[]
repositories {
    ivy {
        url "http://repo.mycompany.com/repo"
        patternLayout {
            artifact "[module]/[revision]/[type]/[artifact].[ext]"
        }
    }
}
// end::ivy-repo-with-pattern-layout[]

// tag::ivy-repo-with-m2compatible-layout[]
repositories {
    ivy {
        url "http://repo.mycompany.com/repo"
        patternLayout {
            artifact "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
            m2compatible = true
        }
    }
}
// end::ivy-repo-with-m2compatible-layout[]

// tag::ivy-repo-with-custom-pattern[]
repositories {
    ivy {
        url "http://repo.mycompany.com/repo"
        patternLayout {
            artifact "3rd-party-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
            artifact "company-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
            ivy "ivy-files/[organisation]/[module]/[revision]/ivy.xml"
        }
    }
}
// end::ivy-repo-with-custom-pattern[]

// tag::maven-repo-with-metadata-sources[]
repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            mavenPom()
            artifact()
        }
    }
}
// end::maven-repo-with-metadata-sources[]

// tag::maven-repo-with-ignore-gradle-metadata-redirection[]
repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            mavenPom()
            artifact()
            ignoreGradleMetadataRedirection()
        }
    }
}
// end::maven-repo-with-ignore-gradle-metadata-redirection[]

// tag::authenticated-ivy-repo[]
repositories {
    ivy {
        url "http://repo.mycompany.com"
        credentials {
            username "user"
            password "password"
        }
    }
}
// end::authenticated-ivy-repo[]

task lookup {
    doLast {
        repositories.each { assert it.name }
        assert repositories[0].name
    }
}

// tag::digest-authentication[]
repositories {
    maven {
        url 'https://repo.mycompany.com/maven2'
        credentials {
            username "user"
            password "password"
        }
        authentication {
            digest(DigestAuthentication)
        }
    }
}
// end::digest-authentication[]

// tag::preemptive-authentication[]
repositories {
    maven {
        url 'https://repo.mycompany.com/maven2'
        credentials {
            username "user"
            password "password"
        }
        authentication {
            basic(BasicAuthentication)
        }
    }
}
// end::preemptive-authentication[]
