<br />

<br />


[Apache Maven](http://maven.apache.org/) is a
build automation tool for Java.

App Engine provides a Maven plugin that you can use to build and deploy
your app to App Engine. The plugin does not support Enterprise
Application Archive (EAR) projects.

> [!NOTE]
> **Note:** For information about other ways to build and deploy your app, see [Testing and deploying your app](https://docs.cloud.google.com/appengine/docs/standard/testing-and-deploying-your-app).

## Before you start

1. Determine if Maven is installed and which version you have by running
   the following command:

       mvn -v

   If Maven is installed, a long string of information beginning with
   `Apache Maven` and followed by a version number such as `3.9.1` will
   display.
2. If you don't have Maven 3.9.1 or newer installed:

   1. [Download](https://maven.apache.org/download.cgi) Maven 3.9.1 or newer.
   2. [Install](https://maven.apache.org/install.html) Maven 3.9.1 or newer.

   Default Linux package managers, such as `apt` or `apt-get` on Ubuntu
   and Debian provide older Maven versions and might not include
   Maven 3.9.1 or newer. To install a supported version on Linux,
   download the binary archive directly from the
   [Apache Maven](https://maven.apache.org/download.cgi) site, and
   follow the [installation instructions](https://maven.apache.org/install.html).
3. If you haven't already done so, follow the steps
   [here](https://docs.cloud.google.com/appengine/docs/standard/setting-up-environment)
   to download the gcloud CLI, create your Google Cloud project, and
   initialize your App Engine app.

4. Install the gcloud CLI `app-engine-java` component:

       gcloud components install app-engine-java

## Adding the App Engine Maven plugin

To use the [App Engine Maven plugin](https://github.com/GoogleCloudPlatform/appengine-plugins/tree/main/app-maven-plugin), add the following lines to the `plugins` section in
your project's `pom.xml` file:

    <plugin>
       <groupId>com.google.cloud.tools</groupId>
       <artifactId>appengine-maven-plugin</artifactId>
       <version>2.8.7</version>
    </plugin>

> [!NOTE]
> **Note:** If there is a newer version of the App Engine Maven plugin, you should upgrade to the [latest version](http://mvnrepository.com/artifact/com.google.cloud.tools/appengine-maven-plugin).

## Building and deploying your app

After you add the App Engine Maven plugin to your project's `pom.xml`
file, you can use the following command to build deploy your app:

```
mvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID
```

Replace <var translate="no">PROJECT_ID</var> with the ID of your Google Cloud project. If
your `pom.xml` file already

[specifies your
project ID](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/maven-reference#appenginedeploy)
, you don't need to include the `-Dapp.deploy.projectId` property in the
command you run.

The `package` goal builds and packages your app, and the

[`appengine:deploy` goal](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/maven-reference#appenginedeploy)

does the following:

1. Generates a unique version ID for the new version of your app.

2. Deploys the new version to App Engine.

3. Routes all traffic to the new version.

## Changing the deployment defaults

You can change the default deployment behavior by passing parameters in the
`appengine:deploy` command. For example, the following command deploys the
service defined in your `pom.xml` file to a specific Google Cloud project,
assigns a custom version ID to the service, and turns off automatic traffic
routing for the new version:

```bash
mvn appengine:deploy -Dapp.deploy.projectId=PROJECT_ID -Dapp.deploy.version=VERSION_ID -Dapp.deploy.promote=False
```

You can also use the `appengine:deploy` command to deploy configuration files,
such as `cron.yaml`, `dispatch.yaml`, and `index.yaml`.

For more information, see the `appengine:deploy`

[reference](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/maven-reference#appenginedeploy)
.

## What's next

- Review the [JDK 21 App Engine Maven plugin sample](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/appengine-java21/helloworld).
- Explore the plugin code and report issues on [GitHub](https://github.com/GoogleCloudPlatform/app-maven-plugin).
- Learn how to specify parameters for tasks by referring to [App Engine Maven Goals and Parameters](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/maven-reference#appenginedeploy).