需要引入插件:
Groovy
io.spring.dependency-management
具体使用参考文档:Dependency Management Plugin
build.gralde配置具体变更,plugins中需要添加插件:io.spring.dependency-management,因为是springboot项目还需要声明插件:org.springframework.boot。
Groovy
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13' apply false
id 'io.spring.dependency-management' version '1.1.7' apply false
}
上述三个插件,其中Java插件跟项目以及所有子模块都需要应用,org.springframework.boot。插件只需要启动模块应用,dependency management插件所有子模块需要应用。因为另外两个插件,在根项目中不应用插件,所以apply写false。在 build.gradle文件中需要添加如下配置:
Groovy
subprojects {
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
}
在build.gradle文件中,subprojects标签下需要添加dependency management,并引入org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES。以及添加下spring中没有管理到的jar包。
Groovy
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
// 统一管理所有依赖版本
dependencies {
dependency "com.baomidou:mybatis-plus-boot-starter:3.5.12"
dependency "com.baomidou:mybatis-plus-generator:3.5.12"
dependency "com.alibaba:druid-spring-boot-starter:1.2.8"
dependency "com.github.pagehelper:pagehelper-spring-boot-starter:1.4.1"
dependency "com.github.ulisesbocchio:jasypt-spring-boot-starter:2.1.0"
dependency "com.alibaba:fastjson:1.2.83"
dependency "dom4j:dom4j:1.6.1"
dependency "com.google.zxing:core:3.3.0"
dependency "com.alibaba:easyexcel:3.3.4"
dependency "com.jcraft:jsch:0.1.54"
dependency "io.springfox:springfox-swagger2:3.0.0"
dependency "com.github.xiaoymin:knife4j-spring-ui:3.0.3"
dependency "com.auth0:java-jwt:3.10.3"
dependency "net.sourceforge.tess4j:tess4j:5.8.0"
}
}
如果项目中所有子模块都需要引入一些炸包,可以统一在根项目的build.gradle文件中设置。在subprojects标签下添加
Groovy
dependencies {
// web 排除内置tomcat,改用undertow
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
implementation 'org.springframework.boot:spring-boot-starter-undertow'
// 参数校验
implementation 'org.springframework.boot:spring-boot-starter-validation'
// mybatis-plus
implementation "com.baomidou:mybatis-plus-boot-starter"
// 分页插件
implementation "com.github.pagehelper:pagehelper-spring-boot-starter:"
// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// swagger knife4j
implementation "io.springfox:springfox-swagger2"
implementation "com.github.xiaoymin:knife4j-spring-ui"
// 工具类
implementation 'org.apache.commons:commons-lang3'
}
子模块中只需要引入自己需要jar。在子模块的build.gradle文件中(这就是完整内容)
Groovy
dependencies {
// 模块依赖
implementation project(':common')
// jwt token
implementation "com.auth0:java-jwt"
}
再添加下相关编码设置后,根模块下的完整build.gradle:
Groovy
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13' apply false
id 'io.spring.dependency-management' version '1.1.7' apply false
}
allprojects {
group = 'com.erbaoge'
version = '1.0-SNAPSHOT'
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
}
subprojects {
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
// 统一管理所有依赖版本
dependencies {
dependency "com.baomidou:mybatis-plus-boot-starter:3.5.12"
dependency "com.baomidou:mybatis-plus-generator:3.5.12"
dependency "com.alibaba:druid-spring-boot-starter:1.2.8"
dependency "com.github.pagehelper:pagehelper-spring-boot-starter:1.4.1"
dependency "com.github.ulisesbocchio:jasypt-spring-boot-starter:2.1.0"
dependency "com.alibaba:fastjson:1.2.83"
dependency "dom4j:dom4j:1.6.1"
dependency "com.google.zxing:core:3.3.0"
dependency "com.alibaba:easyexcel:3.3.4"
dependency "com.jcraft:jsch:0.1.54"
dependency "io.springfox:springfox-swagger2:3.0.0"
dependency "com.github.xiaoymin:knife4j-spring-ui:3.0.3"
dependency "com.auth0:java-jwt:3.10.3"
dependency "net.sourceforge.tess4j:tess4j:5.8.0"
}
}
dependencies {
// web 排除内置tomcat,改用undertow
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
implementation 'org.springframework.boot:spring-boot-starter-undertow'
// 参数校验
implementation 'org.springframework.boot:spring-boot-starter-validation'
// mybatis-plus
implementation "com.baomidou:mybatis-plus-boot-starter"
// 分页插件
implementation "com.github.pagehelper:pagehelper-spring-boot-starter:"
// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// swagger knife4j
implementation "io.springfox:springfox-swagger2"
implementation "com.github.xiaoymin:knife4j-spring-ui"
// 工具类
implementation 'org.apache.commons:commons-lang3'
}
}
启动模块创建启动类后,是能直接启动的,但打包并部署springboot启动包。需要在启动模块应用插件,在启动模块的build.gradle文件中添加
Groovy
apply plugin:'org.springframework.boot'
引入相关依赖后,启动模块完整的build.gradle文件:
Groovy
apply plugin:'org.springframework.boot'
dependencies {
implementation project(':common')
implementation project (':schedule')
implementation project (':login')
implementation project (':notice')
implementation project (':BillPage')
implementation project (':log')
implementation project (':permission')
implementation project (':config')
implementation project (':file')
// 阿里druid连接池
implementation "com.alibaba:druid-spring-boot-starter"
// mysql驱动 runtime范围
runtimeOnly 'com.mysql:mysql-connector-j'
// easyexcel excel导入导出
implementation "com.alibaba:easyexcel"
// 二维码条形码
implementation "com.google.zxing:core"
// sftp
implementation "com.jcraft:jsch"
// httpclient
implementation 'org.apache.httpcomponents:httpclient'
// xml dom4j
implementation "dom4j:dom4j"
// fastjson
implementation "com.alibaba:fastjson"
// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// 配置加密 jasypt
implementation "com.github.ulisesbocchio:jasypt-spring-boot-starter"
implementation 'net.sourceforge.tess4j:tess4j'
// 测试依赖
testImplementation 'junit:junit'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}