config.gradle(依赖版本配置)

// 依赖版本管理
ext {
    version = [
            "springBootVersion" : "2.3.7.RELEASE",
            "fastjsonVersion"   : "1.2.72",
            "lombokVersion"     : "1.18.12",
            "commonsLangVersion": "2.6",
            "jodaTimeVersion"   : "2.10.5",
            "MPVersion"         : "3.4.2",
            "JWTVersion"        : "3.12.0",
            "jdk15onVersion"    : "1.65",
            "jasyptVersion"     : "2.0.0",
            "captchaVersion"    : "1.6.2",
            "ehcacheVersion"    : "2.10.6",
            "hutoolVersion"     : "5.5.8",
            "ajCaptchaVersion"  : "1.2.8",
    ]

    dependencies = [
            "fastjson"                      : "com.alibaba:fastjson:${version.fastjsonVersion}",
            "lombok"                        : "org.projectlombok:lombok:${version.lombokVersion}",
            "commons-lang"                  : "commons-lang:commons-lang:${version.commonsLangVersion}",
            "joda-time"                     : "joda-time:joda-time:${version.jodaTimeVersion}",
            "mybatis-plus-boot-starter"     : "com.baomidou:mybatis-plus-boot-starter:${version.MPVersion}",
            "java-jwt"                      : "com.auth0:java-jwt:${version.JWTVersion}",
            "bcprov-jdk15on"                : "org.bouncycastle:bcprov-jdk15on:${version.jdk15onVersion}",
            "bcpkix-jdk15on"                : "org.bouncycastle:bcpkix-jdk15on:${version.jdk15onVersion}",
            "jasypt-spring-boot-starter"    : "com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.3",
            "druid-spring-boot-starter"     : "com.alibaba:druid-spring-boot-starter:1.1.17",

            "mysql"                         : "mysql:mysql-connector-java:8.0.11",
            "oracle"                        : "com.oracle:ojdbc6:11.2.0.3",
            "sqlserver"                     : "com.microsoft.sqlserver:sqljdbc4:4.0",
            "postgresql"                    : "org.postgresql:postgresql:42.2.18",
            "mongo"                         : "org.mongodb:mongo-java-driver:3.11.0",

            "easy-captcha"                  : "com.github.whvcse:easy-captcha:${version.captchaVersion}",
            "ehcache"                       : "net.sf.ehcache:ehcache:${version.ehcacheVersion}",
            "commons-configuration"         : "commons-configuration:commons-configuration:1.10",
            "velocity"                      : "org.apache.velocity:velocity:1.7",
            "commons-io"                    : "commons-io:commons-io:2.4",
            "pagehelper-spring-boot-starter": "com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0",
            "hutool-all"                    : "cn.hutool:hutool-all:${version.hutoolVersion}",
            "ajCaptcha"                    : "com.anji-plus:spring-boot-starter-captcha:${version.ajCaptchaVersion}",
    ]
}

build.gradle(父模块)

plugins {
    id 'org.springframework.boot' version '2.3.7.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}

apply from: "config.gradle"
// 所有模块/项目的通用配置
allprojects {
    group = 'com.smile'
    version = '0.0.1'
    apply plugin: 'io.spring.dependency-management'
    repositories {
//maven仓库
        mavenLocal()
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
        mavenCentral()
    }
}
// 子模块/项目的统一配置
subprojects {
    apply plugin: 'java'
    // 指定JDK版本
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
    // 指定编码格式
    [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

    // dependencyManagement版本统一管理,类似于父maven的dependencyManagement
    dependencyManagement {
        dependencies {
            for(depJar in rootProject.ext.dependencies){
                dependency depJar.value
            }
        }
    }

    // 子项目依赖,类似于在父maven的dependencies 
    dependencies {
        //lombok
        annotationProcessor 'org.projectlombok:lombok'
        compileOnly 'org.projectlombok:lombok'
        testAnnotationProcessor 'org.projectlombok:lombok'
        testCompileOnly 'org.projectlombok:lombok'

        compile "com.alibaba:fastjson"
        compile "commons-lang:commons-lang"
        implementation(enforcedPlatform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
        compile 'org.springframework.boot:spring-boot-starter-web'
        compile 'org.springframework.boot:spring-boot-starter-log4j2'
        compile 'org.springframework.boot:spring-boot-starter-validation'
        compile ('org.springframework.boot:spring-boot-starter-test')
        compile (rootProject.ext.dependencies["mybatis-plus-boot-starter"]){
            exclude group: 'com.baomidou', module: 'mybatis-plus-generator'
        }
    }
    configurations {
        //移除spring boot 默认logger依赖
        all*.exclude module: 'spring-boot-starter-logging'
    }
}

子模块直接使用即可,无需写版本号:

dependencies {
    compile project(":smile-common")
    compile project(":smile-security")
    compile project(":smile-sys")
    compile "com.alibaba:druid-spring-boot-starter"
    compile "mysql:mysql-connector-java"
}

补充:

打war包配置

buildscript {
    ext {
        springBootVersion = '2.3.7.RELEASE'
    }
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        mavenCentral();
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'com.github.shalousun:smart-doc-gradle-plugin:2.0.7-release'
    }
}
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

bootWar {
    archiveFileName='security.war'
}

打jar包配置

buildscript {
    ext {
        springBootVersion = '2.3.7.RELEASE'
    }
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        mavenCentral();
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'com.github.shalousun:smart-doc-gradle-plugin:2.0.7-release'
    }
}
apply plugin: 'org.springframework.boot'

smartdoc配置

apply plugin: 'com.github.shalousun.smart-doc'
smartdoc {
    configFile = file("src/main/resources/smart-doc.json")

    // exclude example
    // exclude artifact
    exclude 'org.springframework.boot:spring-boot-starter-tomcat'
    // exclude artifact use pattern
    exclude 'org.springframework.boot.*'
    // 你可以使用include配置来让插件自动加载指定依赖的source.
    include 'org.springframework.boot:spring-boot-starter-tomcat'
}

项目层级

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐