gradle environment installation
1 gradle download
gradle-5.6.4-bin.zip .
Gradle historical version released .
2 unzip gradle
Unzip gradle-5.6.4-bin.zip to the local directory D:\dev\gradle5.6.4
3 Add environment variables
GRADLE_HOME
%GRADLE_HOME%\bin
4 Verify that the installation was successful
gradle -v
5 Configure Gradle to use maven local warehouse
Configure gradle to use the jar package of the maven local warehouse, thus saving time and space.
Configure environment variables: GRADLE_USER_HOME
The variable value is the path of the maven local warehouse, such as:
D:\devRepos\mavenRepo
At this point, the files downloaded by Gradle will be placed in the specified warehouse path.
6 gradle configuration global warehouse
.Create a file GRADLE_USER_HOME
in the directory corresponding to the system environment variableinit.gradle
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all {
ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
7 Modify the build.gradle of the construction project
Generally, Gradle and maven download dependency packages from the central warehouse mavenCentral () http://repo1.maven.org/maven2/.
Use domestic mirrors:
repositories {
//repositories闭包
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
mavenLocal() //配置先从本地仓库寻找jar包,优先寻找上一个配置,找到不执行下面的配置
mavenCentral() //配置从中央仓库寻找
google() //第三方仓库
jcenter() //代码托管库:设置之后可以在项目中轻松引用jcenter上的开源项目
}
8 gradle common commands
gradle compile test
#编译(含单元测试)
gradle build
#编译(跳过单元测试)
gradle build -x test
#单元测试
gradle test
#安装到本地maven仓库
gradle install
#清空所有编译、打包生成的文件,会清空build目录
gradle clean
#运行项目
gradle run
#源码打jar包,生成的jar在build/libs目录下
gradle sourcesJar
#生成eclipse结构
gradle eclipse -x :eclipse
#生成pom.xml文件,在build根目录下。把它复制项目根目录下,即可将gradle方便转成maven项目
gradle createPom