Ali cloud maven mirror library configuration (gradle maven)

  • 2021-01-18 06:24:29
  • OfStack

For those who often use the jar package in the maven remote warehouse, the most troublesome thing is that after adding the jar package dependency configuration, they need to download the jar package for a long time. Because the maven warehouse website is a foreign website, the speed is very slow. In the domestic good jar package into the local load again too troublesome.

There used to be a domestic oschina maven mirror warehouse address, now should be abandoned (I have to wait for half a day) now the main domestic use of Ali cloud maven mirror warehouse, very fast ~~~

gradle configuration: Replace mavenCentral() directly or in front of this (default is from top to bottom, so in front of mavenCentral, if added after mavenCentral, it is equivalent to not added)


repositories {
    maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    mavenLocal()
    mavenCentral()
  }

maven configuration:


<repositories>
    <repository>
      <id>aliyunmaven</id>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </repository>
  </repositories>

Question 2: How to use domestic mirroring

If you use maven

Find settings. xml and set the source. Here we use Ali cloud source, the speed is still quite fast.


<mirror>
   <id>alimaven</id>
   <name>aliyun maven</name>
   <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
   <mirrorOf>central</mirrorOf>
</mirror>

If you use gradle

Create a new file init.gradle under USER_HOME/.gradle /, enter the following and save.


allprojects{
  repositories {
    def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
    all { ArtifactRepository repo ->
      if(repo instanceof MavenArtifactRepository){
        def url = repo.url.toString()
        if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
          project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
          remove repo
        }
      }
    }
    maven {
      url REPOSITORY_URL
    }
  }
}


Related articles: