Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Gradle mavenCentral URL to My repo

While working with Gradle in my country, download jars from maven central is a very timely-costed work.
I wanna change the mavenCentral to maven-nexus:
which means whenever I use mavenCentral it always points to oschina

------edit------
I have lots of projects with mavenCentral, so I do not want change each file.

Now in new scripts I use maven{ url ...} Any easy way??

Any one can hlep?
Thanks!

like image 589
Kevin Avatar asked Nov 21 '14 08:11

Kevin


1 Answers

The easiest way to apply this change for all projects is to use an gradle init script that forces the use of the oschina repository instead of mavenCentral. you can put this:

allprojects{
    repositories {
        all { ArtifactRepository repo ->
            println repo.url.toString()
            if ((repo instanceof MavenArtifactRepository) && repo.url.toString().startsWith("https://repo1.maven.org/maven2")) {
                project.logger.warn "Repository ${repo.url} removed. Only $coporateRepoUrl is allowed"
                remove repo
            }   
        }
        maven { 
            url "http://maven.oschina.net/content/groups/public" 
        }
    }
}

into an gradle init file. Now you can use this by calling "gradle build -I yourInitFile.gradle" or you put this logic into a init.gradle file stored in your gradle home directory in USER_HOME/.gradle/ directory. Now this will be picked up by every gradle invocation without explicitly setting -I

Another option is to create a custom gradle distribution where this file is store in the init.d directory of the distribution.

like image 83
Rene Groeschke Avatar answered Oct 05 '22 22:10

Rene Groeschke