# 10.1.1. Maven安装

Spring Boot兼容Apache Maven 3.2或更高版本。如果本地没有安装Maven，你可以参考[maven.apache.org](http://maven.apache.org/)上的指南。

**注**：在很多操作系统上，可以通过包管理器来安装Maven。如果你使用OSX Homebrew，尝试`brew install maven`。Ubuntu用户可以运行`sudo apt-get install maven`。使用Chocolatey的Windows用户可以以管理员身份在命令提示符上运行`choco install maven`。

Spring Boot依赖使用的groupId为`org.springframework.boot`。通常，你的Maven POM文件会继承`spring-boot-starter-parent`工程，并声明一个或多个[“Starter POMs”](https://github.com/jack80342/spring-boot/tree/25350df33f8edd68b50ff6f6e1258c9df4f67d67/III.%20Using%20Spring%20Boot/13.4.%20Starter%20POMs.md)依赖。此外，Spring Boot提供了一个可选的[Maven插件](https://github.com/jack80342/spring-boot/tree/25350df33f8edd68b50ff6f6e1258c9df4f67d67/VIII.%20Build%20tool%20plugins/58.%20Spring%20Boot%20Maven%20plugin.md)，用于创建可执行jars。

下面是一个典型的pom.xml文件：

```markup
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
```

**注**：`spring-boot-starter-parent`是使用Spring Boot的一种不错的方式，但它并不总是最合适的。有时你可能需要继承一个不同的父POM，或是不喜欢我们的默认配置。这些情况，请查看[章节 13.2.2，在不使用parent POM的情况下玩转Spring Boot](https://github.com/jack80342/spring-boot/tree/25350df33f8edd68b50ff6f6e1258c9df4f67d67/III.%20Using%20Spring%20Boot/13.1.2.%20Using%20Spring%20Boot%20without%20the%20Parent%20POM.md)。
