Gradle installation and use of maven repository configuration
One, Gradle installation
1. Installation prerequisites
Installation environment : jdk8 and above
2. Installation steps
Gradle version installed this time: gradle-5.6
- 1. Download the
download address of Gradle's official website: https://gradle.org/releases/ , download and select according to your needs.
Directory structure after decompression:
- 2. Copy the decompressed directory path, for example: D:\Program Files\gradle\gradle-5.6
- 3. Configure system environment variables:
edit path and create a new %GRADLE_HOME5.6%\bin
4. Verify installation
Open cmd and enter the verification command:gradle -v
orgradle -version
Two, use maven warehouse configuration
1. Reasons for configuring and using maven local warehouse :
Reduce the need to re-download the jar package that already exists in the local maven warehouse when Gradle is built, thus saving time and space.
2. Configuration method
2-1. Add a new system variable in the environment variable: GRADLE_USER_HOME, the variable value is the path of the maven local warehouse, this article is an example: D:\Program Files\maven\apache-maven-3.6.1\repository
2-2. Add the configuration to load the jar globally, in the init.d directory under the gradle installation directory.
allprojects {
repositories {
maven {
url 'file:///D:/Program Files/maven/apache-maven-3.6.1/repository'}
mavenLocal()
maven {
name "Alibaba" ; url "http://maven.aliyun.com/nexus/content/groups/public/" }
mavenCentral()
google()
jcenter()
}
buildscript {
repositories {
maven {
name "Alibaba" ; url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
}
2-3. Project settings. Need to modify the build.gradle file to add mavenLocal() to reference the local warehouse
repositories {
//repositories闭包
mavenLocal() //配置先从本地仓库寻找jar包,优先寻找上一个配置,找到不执行下面的配置
mavenCentral() //配置从中央仓库寻找
google() //第三方仓库
jcenter() //代码托管库:设置之后可以在项目中轻松引用jcenter上的开源项目
}
Three, configure gradle in IDEA
First, you need to import the project in the idea (it can be an empty folder), select the import project construction method as: Gradle
and then set the gradle
and the configuration is complete.