# 6.1. 构建系统

[*强烈建议您选择支持依赖关系管理*](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.build-systems.dependency-management)并且可以使用发布到“Maven Central”存储库的工件的构建系统。我们建议您选择 Maven 或 Gradle。Spring Boot 可以与其他构建系统（例如 Ant）一起使用，但它们并没有得到很好的支持。

**6.1.1. 依赖管理**

Spring Boot 的每个版本都提供了它支持的依赖项的精选列表。实际上，您不需要在构建配置中为任何这些依赖项提供版本，因为 Spring Boot 会为您管理它。当您升级 Spring Boot 本身时，这些依赖项也会以一致的方式升级。

> 如果需要，您仍然可以指定版本并覆盖 Spring Boot 的建议。

精选列表包含可与 Spring Boot 一起使用的所有 Spring 模块以及第三方库的精炼列表。该列表作为标准物料清单 (`spring-boot-dependencies`) 提供，可与[Maven](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.build-systems.maven)和[Gradle](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.build-systems.gradle)一起使用。

> Spring Boot 的每个版本都与 Spring 框架的基本版本相关联。我们**强烈**建议您不要指定其版本。

**6.1.2. Maven**

要了解如何将 Spring Boot 与 Maven 结合使用，请参阅 Spring Boot 的 Maven 插件的文档：

* 参考（[HTML](https://docs.spring.io/spring-boot/docs/3.2.0/maven-plugin/reference/htmlsingle/)和[PDF](https://docs.spring.io/spring-boot/docs/3.2.0/maven-plugin/reference/pdf/spring-boot-maven-plugin-reference.pdf)）
* [应用程序编程接口](https://docs.spring.io/spring-boot/docs/3.2.0/maven-plugin/api/)

**6.1.3. Gradle**

要了解如何将 Spring Boot 与 Gradle 结合使用，请参阅 Spring Boot 的 Gradle 插件的文档：

* 参考（[HTML](https://docs.spring.io/spring-boot/docs/3.2.0/gradle-plugin/reference/htmlsingle/)和[PDF](https://docs.spring.io/spring-boot/docs/3.2.0/gradle-plugin/reference/pdf/spring-boot-gradle-plugin-reference.pdf)）
* [应用程序编程接口](https://docs.spring.io/spring-boot/docs/3.2.0/gradle-plugin/api/)

**6.1.4. Ant**

可以使用 Apache Ant+Ivy 构建 Spring Boot 项目。“AntLib”模块`spring-boot-antlib`也可用于帮助 Ant 创建可执行 jar。

要声明依赖项，典型的`ivy.xml`文件类似于以下示例：

```
<ivy-module version="2.0">
    <info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
    <configurations>
        <conf name="compile" description="everything needed to compile this module" />
        <conf name="runtime" extends="compile" description="everything needed to run this module" />
    </configurations>
    <dependencies>
        <dependency org="org.springframework.boot" name="spring-boot-starter"
            rev="${spring-boot.version}" conf="compile" />
    </dependencies>
</ivy-module>
```

典型的`build.xml`示例如下所示：

```
<project
    xmlns:ivy="antlib:org.apache.ivy.ant"
    xmlns:spring-boot="antlib:org.springframework.boot.ant"
    name="myapp" default="build">
​
    <property name="spring-boot.version" value="3.2.0" />
​
    <target name="resolve" description="--> retrieve dependencies with ivy">
        <ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />
    </target>
​
    <target name="classpaths" depends="resolve">
        <path id="compile.classpath">
            <fileset dir="lib/compile" includes="*.jar" />
        </path>
    </target>
​
    <target name="init" depends="classpaths">
        <mkdir dir="build/classes" />
    </target>
​
    <target name="compile" depends="init" description="compile">
        <javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" />
    </target>
​
    <target name="build" depends="compile">
        <spring-boot:exejar destfile="build/myapp.jar" classes="build/classes">
            <spring-boot:lib>
                <fileset dir="lib/runtime" />
            </spring-boot:lib>
        </spring-boot:exejar>
    </target>
</project>
```

如果您不想使用该`spring-boot-antlib`模块，请参阅[*在不使用 spring-boot-antlib 的情况下从 Ant 构建可执行存档*](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.build.build-an-executable-archive-with-ant-without-using-spring-boot-antlib)“操作方法”。

**6.1.5. 初学者**

Starters 是一组方便的依赖描述符，您可以将其包含在应用程序中。您可以获得所需的所有 Spring 和相关技术的一站式商店，而无需寻找示例代码和复制粘贴依赖描述符负载。例如，如果您想开始使用 Spring 和 JPA 进行数据库访问，请`spring-boot-starter-data-jpa`在项目中包含依赖项。

启动器包含许多使项目快速启动和运行所需的依赖项，并具有一致的、受支持的托管传递依赖项集。

名字里有什么

所有**正式**启动器都遵循类似的命名模式；`spring-boot-starter-*`，其中`*`是特定类型的应用程序。这种命名结构旨在帮助您找到入门者。许多 IDE 中的 Maven 集成允许您按名称搜索依赖项。例如，安装了适当的 Eclipse 或 Spring Tools 插件后，您可以`ctrl-space`在 POM 编辑器中按 并键入“spring-boot-starter”以获得完整列表。

[正如“创建您自己的启动器](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.developing-auto-configuration.custom-starter)”部分中所述，第三方启动器不应以 `spring-boot`开头，因为它是为官方 Spring Boot 工件保留的。相反，第三方启动器通常以项目名称开头。例如，名为`thirdpartyproject` 的第三方启动项目通常会命名为`thirdpartyproject-spring-boot-starter`。

Spring Boot 在`org.springframework.boot`组下提供了以下应用程序启动器：

| 姓名                                                | 描述                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `spring-boot-starter`                             | 核心启动器，包括自动配置支持、日志记录和 YAML                                                                                                                                                                                                                                                                               |
| `spring-boot-starter-activemq`                    | 使用 Apache ActiveMQ 的 JMS 消息传递入门                                                                                                                                                                                                                                                                         |
| `spring-boot-starter-amqp`                        | 使用 Spring AMQP 和 Rabbit MQ 的入门程序                                                                                                                                                                                                                                                                        |
| `spring-boot-starter-aop`                         | 使用 Spring AOP 和 AspectJ 进行面向方面编程的入门程序                                                                                                                                                                                                                                                                   |
| `spring-boot-starter-artemis`                     | 使用 Apache Artemis 的 JMS 消息传递入门程序                                                                                                                                                                                                                                                                        |
| `spring-boot-starter-batch`                       | 使用 Spring Batch 的启动器                                                                                                                                                                                                                                                                                    |
| `spring-boot-starter-cache`                       | 使用 Spring 框架的缓存支持的入门程序                                                                                                                                                                                                                                                                                  |
| `spring-boot-starter-data-cassandra`              | 使用 Cassandra 分布式数据库和 Spring Data Cassandra 的入门程序                                                                                                                                                                                                                                                        |
| `spring-boot-starter-data-cassandra-reactive`     | 使用 Cassandra 分布式数据库和 Spring Data Cassandra Reactive 的入门程序                                                                                                                                                                                                                                               |
| `spring-boot-starter-data-couchbase`              | 使用 Couchbase 面向文档的数据库和 Spring Data Couchbase 的入门程序                                                                                                                                                                                                                                                      |
| `spring-boot-starter-data-couchbase-reactive`     | 使用 Couchbase 面向文档的数据库和 Spring Data Couchbase Reactive 的入门程序                                                                                                                                                                                                                                             |
| `spring-boot-starter-data-elasticsearch`          | 使用 Elasticsearch 搜索和分析引擎以及 Spring Data Elasticsearch 的入门程序                                                                                                                                                                                                                                              |
| `spring-boot-starter-data-jdbc`                   | 使用 Spring Data JDBC 的入门程序                                                                                                                                                                                                                                                                               |
| `spring-boot-starter-data-jpa`                    | 将 Spring Data JPA 与 Hibernate 结合使用的入门程序                                                                                                                                                                                                                                                                 |
| `spring-boot-starter-data-ldap`                   | 使用 Spring Data LDAP 的入门程序                                                                                                                                                                                                                                                                               |
| `spring-boot-starter-data-mongodb`                | 使用 MongoDB 面向文档的数据库和 Spring Data MongoDB 的入门程序                                                                                                                                                                                                                                                          |
| `spring-boot-starter-data-mongodb-reactive`       | 使用 MongoDB 面向文档的数据库和 Spring Data MongoDB Reactive 的入门程序                                                                                                                                                                                                                                                 |
| `spring-boot-starter-data-neo4j`                  | 使用 Neo4j 图形数据库和 Spring Data Neo4j 的入门程序                                                                                                                                                                                                                                                                 |
| `spring-boot-starter-data-r2dbc`                  | 使用 Spring Data R2DBC 的入门程序                                                                                                                                                                                                                                                                              |
| `spring-boot-starter-data-redis`                  | 通过 Spring Data Redis 和 Lettuce 客户端使用 Redis 键值数据存储的入门程序                                                                                                                                                                                                                                                  |
| `spring-boot-starter-data-redis-reactive`         | 使用 Redis 键值数据存储与 Spring Data Redis 反应式和 Lettuce 客户端的入门程序                                                                                                                                                                                                                                                |
| `spring-boot-starter-data-rest`                   | 使用 Spring Data REST 和 Spring MVC 通过 REST 公开 Spring Data 存储库的入门程序                                                                                                                                                                                                                                        |
| `spring-boot-starter-freemarker`                  | 使用 FreeMarker 视图构建 MVC Web 应用程序的入门程序                                                                                                                                                                                                                                                                    |
| `spring-boot-starter-graphql`                     | 使用 Spring GraphQL 构建 GraphQL 应用程序的入门程序                                                                                                                                                                                                                                                                  |
| `spring-boot-starter-groovy-templates`            | 使用 Groovy 模板视图构建 MVC Web 应用程序的入门程序                                                                                                                                                                                                                                                                      |
| `spring-boot-starter-hateoas`                     | 使用 Spring MVC 和 Spring HATEOAS 构建基于超媒体的 RESTful Web 应用程序的入门程序                                                                                                                                                                                                                                           |
| `spring-boot-starter-integration`                 | 使用 Spring Integration 的入门程序                                                                                                                                                                                                                                                                             |
| `spring-boot-starter-jdbc`                        | 将 JDBC 与 HikariCP 连接池结合使用的入门程序                                                                                                                                                                                                                                                                          |
| `spring-boot-starter-jersey`                      | 使用 JAX-RS 和 Jersey 构建 RESTful Web 应用程序的入门程序。替代方案[`spring-boot-starter-web`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-web)                                                                                                                              |
| `spring-boot-starter-jooq`                        | 使用 jOOQ 通过 JDBC 访问 SQL 数据库的入门程序。[`spring-boot-starter-data-jpa`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-data-jpa)或 的替代方案[`spring-boot-starter-jdbc`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-jdbc) |
| `spring-boot-starter-json`                        | 读取和写入 json 的 Starter                                                                                                                                                                                                                                                                                    |
| `spring-boot-starter-mail`                        | 使用 Java Mail 和 Spring Framework 的电子邮件发送支持的入门程序                                                                                                                                                                                                                                                          |
| `spring-boot-starter-mustache`                    | 使用 Mustache 视图构建 Web 应用程序的入门程序                                                                                                                                                                                                                                                                          |
| `spring-boot-starter-oauth2-authorization-server` | 使用 Spring 授权服务器功能的入门程序                                                                                                                                                                                                                                                                                  |
| `spring-boot-starter-oauth2-client`               | 使用 Spring Security 的 OAuth2/OpenID Connect 客户端功能的入门程序                                                                                                                                                                                                                                                   |
| `spring-boot-starter-oauth2-resource-server`      | 使用 Spring Security 的 OAuth2 资源服务器功能的入门程序                                                                                                                                                                                                                                                                |
| `spring-boot-starter-pulsar`                      | 使用 Spring for Apache Pulsar 的入门程序                                                                                                                                                                                                                                                                       |
| `spring-boot-starter-pulsar-reactive`             | 使用 Spring for Apache Pulsar Reactive 的入门程序                                                                                                                                                                                                                                                              |
| `spring-boot-starter-quartz`                      | 使用 Quartz 调度程序的入门程序                                                                                                                                                                                                                                                                                     |
| `spring-boot-starter-rsocket`                     | 用于构建 RSocket 客户端和服务器的 Starter                                                                                                                                                                                                                                                                           |
| `spring-boot-starter-security`                    | 使用 Spring Security 的入门程序                                                                                                                                                                                                                                                                                |
| `spring-boot-starter-test`                        | 用于使用 JUnit Jupiter、Hamcrest 和 Mockito 等库测试 Spring Boot 应用程序的 Starter                                                                                                                                                                                                                                    |
| `spring-boot-starter-thymeleaf`                   | 使用 Thymeleaf 视图构建 MVC Web 应用程序的入门程序                                                                                                                                                                                                                                                                     |
| `spring-boot-starter-validation`                  | 使用 Hibernate Validator 进行 Java Bean 验证的入门指南                                                                                                                                                                                                                                                             |
| `spring-boot-starter-web`                         | 用于使用 Spring MVC 构建 Web（包括 RESTful）应用程序的入门程序。使用Tomcat作为默认的嵌入式容器                                                                                                                                                                                                                                          |
| `spring-boot-starter-web-services`                | 使用 Spring Web 服务的入门程序                                                                                                                                                                                                                                                                                   |
| `spring-boot-starter-webflux`                     | 使用 Spring Framework 的 Reactive Web 支持构建 WebFlux 应用程序的入门程序                                                                                                                                                                                                                                               |
| `spring-boot-starter-websocket`                   | 使用 Spring Framework 的 MVC WebSocket 支持构建 WebSocket 应用程序的入门程序                                                                                                                                                                                                                                            |

除了应用程序启动器之外，还可以使用以下启动器来添加[*生产就绪*](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator)功能：

| 姓名                             | 描述                                                      |
| ------------------------------ | ------------------------------------------------------- |
| `spring-boot-starter-actuator` | 使用 Spring Boot 的 Actuator 的入门程序，它提供生产就绪的功能来帮助您监视和管理应用程序 |

最后，Spring Boot 还包括以下启动器，如果您想排除或交换特定的技术方面，可以使用它们：

| 姓名                                  | 描述                                                                                                                                                                            |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `spring-boot-starter-jetty`         | 使用 Jetty 作为嵌入式 servlet 容器的入门程序。替代方案[`spring-boot-starter-tomcat`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-tomcat)           |
| `spring-boot-starter-log4j2`        | 使用 Log4j2 进行日志记录的入门程序。替代方案[`spring-boot-starter-logging`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-logging)                  |
| `spring-boot-starter-logging`       | 使用 Logback 进行日志记录的启动器。默认日志记录启动器                                                                                                                                               |
| `spring-boot-starter-reactor-netty` | 使用 Reactor Netty 作为嵌入式反应式 HTTP 服务器的入门程序。                                                                                                                                      |
| `spring-boot-starter-tomcat`        | 使用 Tomcat 作为嵌入式 servlet 容器的入门程序。使用的默认 servlet 容器启动器[`spring-boot-starter-web`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-web) |
| `spring-boot-starter-undertow`      | 使用 Undertow 作为嵌入式 servlet 容器的入门程序。替代方案[`spring-boot-starter-tomcat`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#spring-boot-starter-tomcat)        |

[要了解如何交换技术方面，请参阅交换 Web 服务器](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.webserver.use-another)和[日志系统](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.logging.log4j)的操作方法文档。

> 有关其他社区贡献的入门者的列表，请参阅GitHub 上模块`spring-boot-starters` 中的[自述文件。](https://github.com/spring-projects/spring-boot/tree/main/spring-boot-project/spring-boot-starters/README.adoc)
