Gradle download failure is usually caused by the connection timeout caused by the remote warehouse outside the country, the solution is to change the domestic warehouse source, commonly used is ali warehouse source.

Here are two ways to add ali warehouse source:

I. Separate configuration of the project

Add the repository address to the project root directory build.gradle and add the Repository address under the two repositories nodes:

/ / to omit
buildscript {
    / / to omit
    repositories {
        / / to omit
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        / / to omit
    }
    / / to omit
}
/ / to omit
allprojects {
	/ / to omit
    repositories {
    	/ / to omit
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        / / to omit
    }
    / / to omit
}
/ / to omit
Copy the code

Add the repository address to the root directory setting. Gradle at the beginning:

pluginManagement {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/central'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/grails-core'
        }
        maven {
            url 'https://maven.aliyun.com/repository/apache-snapshots'}}}Copy the code

2. Global configuration

You can configure the initial parameters for Gradle using global configuration.

buildscript {
    repositories {
    	maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
    	}
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
    }
}
allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'}}}Copy the code

Save the above as a file named init.gradle and place it in USER_HOME/. Gradle /, where USER_HOME is C:\Users\ your username on Windows and Linux

cd ~
Copy the code

To enter.

If you find an init.gradle file, add the above to it.

Attached lazy configuration:

buildscript {

    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/central'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/grails-core'
        }
        maven {
            url 'https://maven.aliyun.com/repository/apache-snapshots'
        }

    }

}

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/central'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring'
        }
        maven {
            url 'https://maven.aliyun.com/repository/spring-plugin'
        }
        maven {
            url 'https://maven.aliyun.com/repository/grails-core'
        }
        maven {
            url 'https://maven.aliyun.com/repository/apache-snapshots'}}}Copy the code