import org.gradle.util.GradleVersion

static boolean versionAtLeast(String version) {
    return GradleVersion.current() >= GradleVersion.version(version)
}

static void configureRepos(RepositoryHandler repositories) {
    repositories.configureEach { ArtifactRepository repo ->
        if (repo instanceof MavenArtifactRepository) {
            repo.setArtifactUrls(new HashSet<URI>())
            repo.url 'file:@mavenRepo@'
            repo.metadataSources {
                gradleMetadata()
                mavenPom()
                artifact()
            }
        } else if (repo instanceof IvyArtifactRepository) {
            repo.url 'file:@mavenRepo@'
            repo.layout('maven')
            repo.metadataSources {
                gradleMetadata()
                ivyDescriptor()
                artifact()
            }
        } else if (repo instanceof UrlArtifactRepository) {
            repo.url 'file:/homeless-shelter'
        }
    }
}

beforeSettings { settings ->
    configureRepos(settings.pluginManagement.repositories)
    configureRepos(settings.buildscript.repositories)
    if (versionAtLeast("6.8")) {
        configureRepos(settings.dependencyResolutionManagement.repositories)
    }
}

beforeProject { project ->
    configureRepos(project.buildscript.repositories)
    configureRepos(project.repositories)
}
