gradle|springboot+gradle多模块化应用

gradle多模块化


现在单体应用很少了,通常会分为以下几个模块:
1.提供给后台操作的admin模块
2.提供给RPC远程调用的 service模块
3.打包提供给别的应用的client 模块
4.对数据库操作及实现接口的 business-impl模块
5.供服务内部调用的manager模块
6.通用的工具类common模块
这里选取Admin和business-impl的代码进行展示:
admin->build.gradle:

plugins {
  id 'org.springframework.boot' version '2.1.6.RELEASE'
  id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'cloud.javastudy.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {

compile project(":demo-business-impl")
  implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
  implementation 'org.springframework.boot:spring-boot-starter-web'
  implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.0'
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

business-impl模块的build.gradle

plugins {
  id 'java'
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {

compile project(":demo-business")

}

总体的拆分模块及包如下图所示:
gradle|springboot+gradle多模块化应用
gradle|springboot+gradle多模块化应用

DEMO总评


多模块化的拆分一般与公司的业务为主,总体来说差别不大,拆分的难点在于gradle的组织方式,这点一般公司也都有模板工程,本DEMO适用于小白学习,真正入职之后,还是要以公司已有的拆分为主. 与Maven的拆分相似,gradle也可以做版本统一管理,不过这个DEMO中没有写出,会在后续的DEMO中给出,加油吧,少年!

猜你喜欢

转载自blog.51cto.com/15082395/2645952
今日推荐