1 Select File - > New - > project, select gradle java and click next
2. Enter the GroupId and artifactid of the project. GroupId is generally represented by domain name inversion, for example: com.ws Artifactid: project code, and then click Next
3 check as shown in the figure below. Use auto import to download jar dependency automatically when the gradle configuration file changes. Check to use the local gradle version, and then click next to generate the project
4 as shown in the figure below
5. After the project is generated, the src directory can be deleted because we are creating multiple module projects. The configuration of gradle multiple projects will be described below
gradle multi project configurationUnder the root project directory build.gradle Add the following configuration to the file
buildscript { ext{ springBootVersion='2.1.6.RELEASE' } repositories { maven { url "http://maven.aliyun.com/nexus/content/groups/public" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:$") } } group 'com.ws' version '1.0-SNAPSHOT' allprojects { repositories { maven { url "http://maven.aliyun.com/nexus/content/groups/public" } } } subprojects { apply plugin: 'java' // plugin is used to keep the version of spring boot dependency library consistent apply plugin: 'org.springframework.boot' apply plugin: 'findbugs' apply plugin: 'maven' apply plugin: "io.spring.dependency-management" compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" dependencyManagement { dependencies { dependency 'ch.qos.logback:logback-classic:1.2.3' dependency 'ch.qos.logback:logback-core:1.2.3' dependency 'com.fasterxml.jackson.core:jackson-databind:2.9.9.3' dependency 'com.fasterxml.jackson.core:jackson-core:2.9.9' dependency 'com.fasterxml.jackson.core:jackson-annotations:2.9.9' dependency 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9' dependency 'com.fasterxml.jackson.module:jackson-module-afterburner:2.9.9' dependency 'com.alibaba:druid:1.1.16' dependency 'com.google.guava:guava:19.0' dependency 'io.netty:netty-codec-http:4.1.8.Final' dependency 'io.netty:netty-transport-native-epoll:4.1.8.Final' dependency 'net.bytebuddy:byte-buddy-agent:1.7.9' dependency 'org.ow2.asm:asm:5.2' dependency 'org.projectlombok:lombok:1.16.18' dependency 'com.google.code.findbugs:jsr305:3.0.2' dependency 'commons-io:commons-io:2.5' dependency 'org.apache.commons:commons-exec:1.3' dependency 'org.apache.commons:commons-lang3:3.5' dependency 'org.apache.commons:commons-collections4:4.1' dependency 'io.projectreactor:reactor-core:3.2.8.RELEASE' } } findbugs { ignoreFailures=true } }
Configuration Description:
Buildscript: for the configuration of gradle build script, you can use ext to configure variable names and values, as well as the plug-ins needed in the build script, and the repositories of plug-ins. Here, we use the spring boot gradle plugin plug-in, which will automatically manage the dependent versions of the introduced spring boot
Subjects: because it is a multi module project, use subject project to manage some dependencies shared by modules
Dependency management: this configuration comes from io.spring.dependency-management, unified management of dependencies, but it will not introduce these dependencies when build.gradle When you use dependencies to import dependencies in module, you can actually import them without specifying the version
A module is equivalent to a subproject
1 select the root directory test, right-click - > New - > module, as shown in the following figure
2. After the module is created, the directory structure is as shown in the figure below
3. Modify the build.gradle Configuration files add dependencies required by the project directly
dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web compile group: 'org.springframework.boot', name: 'spring-boot-starter-web' // https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka compile group: 'org.springframework.kafka', name: 'spring-kafka' }
In this way, the whole project is configured, as shown in the figure below, and a test case is written
5 generate a runnable jar package