- 项目结构
microservice-parent: 统一管理所有模块的 jar 包版本信息
microservice-bean: 统一管理所有模块的用到的 pojo 类
microservice-common:统一管理所有模块的用到的工具类、枚举类、异常处理、日志文件、统一返回结果信息
microservice-service: 统一封装所有的微服务
microservice-gateway: 封装网关信息
rootProject.name = 'microservice'
include 'microservice_bean'
include 'microservice_common'
include 'microservice_gateway'
include 'microservice_service'
include 'microservice_service:service_user'
findProject(':microservice_service:service_user')?.name = 'service_user'
include 'microservice_service:service_order'
findProject(':microservice_service:service_order')?.name = 'service_order'
// 依赖版本管理
ext {
version = [
"fastjsonVersion" : "1.2.72",
"mybatisPlus" : "3.0.5",
"mysql" : "5.1.46",
"swaggerVersion": "2.7.0",
"jjwtVersion": "0.7.0"
]
dependencies = [
"fastjson" : "com.alibaba:fastjson:${version.fastjsonVersion}",
"mybatis-plus-boot-starter" : "com.baomidou:mybatis-plus-boot-starter:${version.mybatisPlus}",
"mysql" : "mysql:mysql-connector-java:${version.mysql}",
"swagger" : "io.springfox:springfox-swagger2:${version.swaggerVersion}",
"swaggerUI" : "io.springfox:springfox-swagger-ui:${version.swaggerVersion}",
"jjwt" : "io.jsonwebtoken:jjwt:${version.jjwtVersion}"
]
}
description '尚硅谷gradle微服务实战父工程'
//构建Gradle脚本自身需要的资源,可以声明的资源包括依赖项、第三方插件、maven仓库地址等。
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
springCloudVersion = 'Hoxton.RELEASE'
springCloudAlibabaVersion = '0.2.2.RELEASE'
}
//设置仓库
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://repo.spring.io/milestone'}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
//配置全局, 包括root项目和子项目
allprojects {
group 'com.atguigu'
version '1.0-SNAPSHOT'
//配置编码格式
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
//设置仓库
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://repo.spring.io/milestone'}
}
}
apply from: 'version.gradle'
//配置所有子项目
subprojects {
apply plugin: 'java'
apply plugin: 'java-library' //api
apply plugin: 'io.spring.dependency-management'
sourceCompatibility= JavaVersion.VERSION_1_8
targetCompatibility= JavaVersion.VERSION_1_8
//公用的依赖
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
// dependencyManagement版本统一管理,类似于父maven的dependencyManagement
dependencyManagement {
dependencies {
for(depJar in rootProject.ext.dependencies){
dependency depJar.value
}
}
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaVersion}"
}
}
}
project(':microservice_bean'){
description("尚硅谷微服务实战之bean层:存放表对应的实体类")
}
project(":microservice_common"){
description("尚硅谷微服务实战之公共模块:存放微服务常用的工具类")
//依赖
dependencies {
api 'com.alibaba:fastjson'
api 'mysql:mysql-connector-java'
api 'com.baomidou:mybatis-plus-boot-starter'
api 'io.springfox:springfox-swagger2'
api 'io.springfox:springfox-swagger-ui'
api 'io.jsonwebtoken:jjwt'
api 'org.springframework.cloud:spring-cloud-starter-openfeign'
api 'org.springframework.cloud:spring-cloud-starter-alibaba-sentinel'
api 'org.springframework.cloud:spring-cloud-starter-alibaba-nacos-discovery'
}
}
project(":microservice_service"){
description("尚硅谷微服务实战之服务模块:存放各个微服务模块")
apply plugin: 'org.springframework.boot'
subprojects {
apply plugin : 'java-library'
apply plugin: 'org.springframework.boot'
dependencies {
api 'org.springframework.boot:spring-boot-starter-web'
api project(':microservice_bean')
api project(':microservice_common')
}
}
}