Refresh-dependecies does not use repository defined in .gradle/init.d script


(Ivica Loncar) #1

Hi,

I would like to use different artifact repository (i.e. local nexus proxy) from the one specified in build.gradle files.
I figured out that I could use init script like the following one to achieve that:

apply plugin:ProxyRepositoryPlugin

class ProxyRepositoryPlugin implements Plugin<Gradle> {

def REPLACEMENTS = [

    "https://corporate.host.com/nexus/content/repositories/public":"http://localhost:8081/repository/xl-public"

    void apply(Gradle gradle) {
        // ONLY USE ENTERPRISE REPO FOR DEPENDENCIES
        gradle.allprojects{ project ->
            project.repositories {
                // Remove all repositories not pointing to the enterprise repository url
                all { ArtifactRepository repo ->
                    if (REPLACEMENTS.containsKey(repo.url.toString())) {
                        def originalUrl = repo.url
                        repo.url = REPLACEMENTS[repo.url.toString()]
                        project.logger.info "Repository ${originalUrl} updated to point to ${repo.url}."
                    } else {
                        project.logger.info "Repository ${repo.url} usage detected."
                    }
                }
            }
        }
    }
}

and it resolved artifacts via local artifact repository, but --refresh-dependencies still goes to the original URL which is a bit slower. Is there a way to use local repo for refresh?