Spring Boot 教程:构建系统

476 阅读1分钟
【注】本文译自:[https://www.tutorialspoint.com/spring_boot/spring_boot_build_systems.htm](https://www.tutorialspoint.com/spring_boot/spring_boot_build_systems.htm)
对于 Spring Boot,选择构建系统是一项重要任务。我们推荐使用 Maven 或 Gradle,因为它们对于依赖管理有良好的支持。Spring对于其他构建系统支持得不是很好。

依赖管理

Spring Boot 团队在每次发布时都提供一支持 Spring Boot 版本的依赖列表。你不需要在构建配置文件中提供依赖的版本。Spring Boot 根据发布自动配置依赖版本。记住你更新 Spring Boot 版本时,会自动更新相关依赖。
注意:如果你想指定依赖的版本,可以在配置文件中指定。然而,Spring Boot 团队强烈推荐没必要指定依赖版本。

Maven 依赖

对于 Maven 配置,我们应当继承 Spring Boot 启动器父项目管理 Spring Boot 启动器依赖。我们的 pom.xml 如下所示:
<parent>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-parent</artifactId>   <version>1.5.8.RELEASE</version></parent>
    我们应用指定 Spring Boot 父启动器依赖的版本号。之后对于其他启动器依赖,我们就没必要再指定 Spring Boot 版本号了。示例如下:
<dependencies>   <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-web</artifactId>   </dependency></dependencies>

Gradle 依赖

我们可以在 build.gradle 文件中直接引入 Spring Boot 启动器依赖。没必要象Maven 一样指定Spring Boot 父启动器依赖,如下所示:
buildscript {   ext {      springBootVersion = '1.5.8.RELEASE'   }   repositories {      mavenCentral()   }   dependencies {      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")   }}
    同样,在 Gradle 中,我们也没必要指定所依赖的 Spring Boot 版本号。Spring Boot 自动配置依赖版本。
dependencies {  compile('org.springframework.boot:spring-boot-starter-web')}