一、创建项目
1、创建主项目
按创建springboot项目的创建方式创建就行,创建完的结构。然后删除src目录。

2、创建模块项目
创建模块项目New-》Module-》New Module(或Spring Initializr)。


依次创建service删除文件,然后创建工程等,创建后如下:

3、setting.gradle文件
创建完工程后,会自动在这个文件中添加下面的内容,表示将子模块引入

二、配置build.gradle文件
构建单体的多模块项目,demo-web作为启动项目,依赖service
说明文档:https://docs.gradle.org/current/userguide/gradle_directories.htmlGradle Directorieshttps://docs.gradle.org/current/userguide/gradle_directories.html
1、修改根目录的build.gradle
用于管理子模块。主要是hi设置下载仓库、依赖包、插件等信息。主要定义一些公共的内容。
打包相关的定义也可以统一在跟目录下的这个文件写,暂时定义到各模块自己的文件里。
buildscript {
// 指定插件的仓库
repositories {
jcenter()
mavenCentral()
maven { url 'https://jitpack.io/' } // 添加这一行
}
// 定义插件及其版本
// dependencies {
// classpath "org.springframework.boot:spring-boot-gradle-plugin:2.5.5"
// }
}
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.7'
id 'io.spring.dependency-management' version '1.1.5'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
// dependencies {
// implementation 'org.springframework.boot:spring-boot-starter'
// }
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.named('test') {
useJUnitPlatform()
}
}
2、修改模块项目的build.gradle
以demo-web为例。增加依赖的项目包,也可以增加其他的依赖
bootJar {
archiveBaseName = 'demo-web'
archiveVersion = '0.0.1-SNAPSHOT'
}
dependencies {
implementation project(':service:demo-api')
implementation project(':service:demo-service')
}
demo-service工程。定义只打jar。bootjar定位false
bootJar {
enabled(false)
archiveBaseName = 'demo-service'
archiveVersion = '0.0.1-SNAPSHOT'
}
jar {
enabled(true)
}
dependencies {
implementation pr

5285

被折叠的 条评论
为什么被折叠?



