springboot-000 multi-module project to build gradle

 Before learned springboot, but because the company is no demand in this area, it has not been used in development, just a little time taking advantage of the recent re going to do next in order, took notes, reinforced the impression.

This is the first chapter springboot build gradle multi-module project.

gradle is a build tool, to help us build App. Including the construction of compilation, packaging and other processes. In gradle, each project is to be compiled in a project, build a project you need to perform a series of task, if you want gradle correct implementation task we need to introduce the corresponding plug-ins. gradle and maven compared with simpler and more flexible configuration, xml configuration maven relative (though easy to understand, but hard to describe if, else, etc. There are different conditions such tasks in xml), gradle flexible groovy simple scripting language greatly simplifies the construction of the number of lines of code, and groovy is java-based and expanded java, java programmers can seamlessly switch groovy development program, is to write java groovy become as simple as writing a script, you can perform finished, groovy will be compiled into an internal java byte code, and then start the virtual machine (JVM) to execute.

The next step is using the idea to build gradle multi-module project, open the idea, select the file, create a project

 

Click next, select the directory where the project groupId, create a project name ArtifactId, Why next, click finish.

After the success of the project directory as follows

 

 

 Then it is to build other modules, click the project name, right-new model, basically no need to modify the following page, click on next, enter ArtifactId, click next, click finish, you can

Finally, the directory structure is as follows:

 

gradle.properties configuration information:

org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

 build.gradle configuration information as follows:

// 指定要应用的插件和版本
plugins {
    id 'java'
    id "org.springframework.boot" version "2.1.2.RELEASE"
    id "io.spring.dependency-management" version "1.0.6.RELEASE"
}

// 指定下载的仓库地址
allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        jcenter()
        mavenCentral()
    }
}

group 'com.pf.springboot'

// 指定依赖版本
ext.spring_cloud_version = "Greenwich.RELEASE"
ext['lombok.version'] = "1.18.4"

// 应用于所有依赖的子项目
subprojects {
    version '1.0-SNAPSHOT'
    // 应用插件
    apply plugin: "java"
    apply plugin: "org.springframework.boot"
    apply plugin: "io.spring.dependency-management"

    // 设置编译和运行的jre兼容版本
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    // 字符编码处理
    def defaultEncoding = 'UTF-8'
    tasks.withType(AbstractCompile).each { it.options.encoding = defaultEncoding }

    // 生成Java文档的任务
    javadoc {
        options.encoding = defaultEncoding
        options.addBooleanOption('Xdoclint:none', true)
    }

    // Java编译任务依赖处理资源的任务
    compileJava.dependsOn(processResources)

    // 指定要运行测试的包
    test {
        include "**/repository/**", "**/service/**", "**/controller/**"
    }

    // spring boot构建任务
    springBoot {
        buildInfo()
    }

    dependencyManagement {
        // 导入maven依赖管理的bom
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${spring_cloud_version}"
            mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
        }
    }

    /*
    * 为所有模块指定公共的依赖
    * 注意这里有些默认不用再指定版本了,已经由上面的dependencyManagement管理了
    * */
    dependencies {
        annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
        annotationProcessor "org.projectlombok:lombok"
        compileOnly "org.springframework.boot:spring-boot-configuration-processor"
        compileOnly "org.projectlombok:lombok"
        implementation "org.apache.commons:commons-lang3"
        implementation "org.apache.commons:commons-collections4:4.3"
        implementation "org.springframework.boot:spring-boot-starter-web"
//        implementation "org.springframework.boot:spring-boot-starter-jdbc"
        implementation fileTree(dir: 'libs', includes: ['*.jar'])
        testAnnotationProcessor "org.projectlombok:lombok"
        testCompileOnly "org.projectlombok:lombok"
        testImplementation "org.springframework.boot:spring-boot-starter-test"
    }
}

至此基本架构已搭建完成

Guess you like

Origin www.cnblogs.com/ly-gaoshuaige/p/12045823.html