gradle 构建springboot分模块项目
时间: 2023-07-21 12:13:57 浏览: 55
构建Spring Boot分模块项目可以通过Gradle的多项目构建功能来实现。下面是一个简单的示例:
首先,在项目根目录下创建一个settings.gradle文件,用于声明多个子项目:
```
rootProject.name = 'my-spring-boot-project'
include 'common'
include 'web'
```
在此示例中,我们将创建两个子项目:common和web。
接下来,为每个子项目创建一个build.gradle文件。在common子项目的build.gradle文件中,添加以下内容:
```
plugins {
id 'java'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// 添加其他依赖项
}
```
在web子项目的build.gradle文件中,添加以下内容:
```
plugins {
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
dependencies {
implementation project(':common')
// 添加其他依赖项
}
```
在这里,我们使用了Spring Boot Gradle插件和Spring Boot依赖管理插件,以便在web模块中使用Spring Boot框架。同时,我们还声明了对common模块的依赖。
最后,在根目录下运行gradle build命令,Gradle将会构建所有子项目,并在web子项目的build/libs目录下生成可执行的jar文件。
这样就完成了Spring Boot分模块项目的构建。当需要添加新的模块时,只需要在settings.gradle文件中声明新的子项目,并在其中添加相应的build.gradle文件即可。