何亦冷

导航

maven和gradle的全局阿里云镜像代理

Maven:~/.m2/settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <!-- 官网参考: http://maven.apache.org/guides/mini/guide-mirror-settings.html -->
    <mirrors>
    
        <!-- 阿里云镜像 -->
        <mirror>
            <id>alimaven</id>
            <name>阿里云中央仓库</name>
            <mirrorOf>central,jcenter</mirrorOf>
            <url>https://maven.aliyun.com/repository/public/</url>
        </mirror>

        <!-- maven3.8.1之后默认阻止http私服的优雅处理方案 -->
        <mirror>
            <id>maven-default-http-blocker</id>
            <mirrorOf>!*</mirrorOf>
            <url>http://0.0.0.0/</url>
        </mirror>

    </mirrors>


</settings>

 

Gradle: ~/.gradle/init.gradle

// 官网参考: https://docs.gradle.org/current/userguide/init_scripts.html#header
allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public/' } 
        maven { url 'https://maven.aliyun.com/repository/google' }        
    }
}

 

// 验证:工程文件的build.gradle加入如下任务,并运行 gradle showRepos
task showRepos {
    doLast {
        repositories.each {
            println "repository: ${it.name} ('${it.url}')"
        }
    }
}

 

 

 

 

 

 

 

 

posted on 2020-07-12 16:32  何亦冷  阅读(2816)  评论(0编辑  收藏  举报