gradle from entry to master

I. Overview

Gradle is based on the configuration of the groovy language. Compared with maven (1, manage jar packages; 2, automatically build projects), it has two major advantages: First, there is no cumbersome xml file. Second, it is more flexible.

Two, install gradle

After downloading------>decompress---------->Configure environment variables

Three, integrated gradle in IDEA

Note: A higher version of gradle requires a higher version of the idea, and an error will be reported Cause: org/gradle/api/internal/plugins/DefaultConvention
Insert picture description here

Fourth, the directory structure introduction

Insert picture description here

5. Getting started with groovy programming language

//定义变量
//def i = 12
//println i

//定义一个集合
//def a = ['ac','ab']
//a << 'dd'
//println a.get(2)

//定义一个map
//def m = ['a':1,'b':2]
//map中添加元素
//m.'c'=3
//打印map
//println m.get('c')



//定义一个闭包,在gradle中的闭包就是一块代码,常用来当从参数
//def b ={
    
    
//    println 123
//}
//定义一个方法
//def method (Closure cou){
    
    
//    cou()
//}

//调用方法
//method(b)


//定义一个有参数的闭包

def b2 = {
    
    
    v ->
        println "${v} 程程"
}

//定义一个方法
def method2(Closure closure){
    
    
    closure("小")
}

//调用方法
method2 (b2)

Six, configuration file introduction

If you need to find dependencies, you can find the corresponding gradle dependencies from the maven official website and copy them
Insert picture description here

Seven, modify gradle warehouse to maven warehouse

7.1. Configure an environment variable GRADLE_USER_HOME + a warehouse path of maven

Check whether the configuration is successful. In the setting of the interface after startup, whether the path in gradle points to the maven warehouse

7.2. Configuration of local warehouse and central warehouse in build.gradle file

//If both mavenLocal() and mavenCentral() are configured, first obtain it locally, if not, then obtain it from the central warehouse
// If only mavenCentral() is configured, it is to download the local from the central warehouse, and download it from the local next time Search for the file, no more
repositories from the central warehouse { mavenLocal() mavenCentral() }


8. How to play jar package

8.1, the first step

Insert picture description here

8.2, the second step is to view the location of the jar package

Insert picture description here

Nine, how to create a web project

9.1. Start creation is the same as the above creation steps, then under the word main, create a directory (directory) webapp-->WEB-INF---->web.xml-------->Add in build.gradle A line of apply plugin:'war' is shown in the figure below. This will make the icon of the webapp directory become normal.

Insert picture description here

Ten, gradle split and aggregation

When building a parent-child project, if you want the child projects to inherit the dependencies of the parent project, you must use allprojects{} to include all of them in the build.gradle file of the parent project. After this operation, almost all the contents of the build.gradle file in the subproject can be deleted.

10.1. The build.gradle file of the parent-child project, if there are common features, you can delete the sub-project. If the sub-projects depend on each other, configure them as shown in the figure below:

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43983411/article/details/112255299