Apache Maven 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.
Before you start
Determine if Maven is installed and which version you have by running the following command:
If Maven is installed, a long string of information beginning with
Apache Mavenand followed by a version number such as
If you don't have Maven 3.5 or newer installed:
If you haven't already done so, follow the steps in the Quickstart to download the Cloud SDK, create your Cloud project, and initialize your App Engine app.
Install the Cloud SDK
gcloud components install app-engine-java
Adding the App Engine Maven plugin
To use the App Engine Maven plugin, add the following lines to the
plugins section in
The App Engine plugin includes the Jetty Maven plugin, which you can use to test your application quickly without creating a WAR file.
<plugins> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>2.4.0</version> </plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.3.7.v20160115</version> </plugin> </plugins>
Using the Jetty Maven plugin to test your app locally
During the development phase, you can run and test your app at any time in the development server by invoking the Jetty Maven plugin.
To run your app in the development server:
Build your app if you haven't already done so:
Change directory to the top level of your project (for example, to
myapp), and run your app by invoking Maven:
Wait for the server to start and use your browser to visit
http://localhost:8080/to access your app.
Shut down the app and the development server by pressing Control+C.
Building and deploying your app
After you add the App Engine Maven plugin to your project's
file, you can use the following command to build deploy your app:
mvn package appengine:deploy -Dapp.deploy.projectId=PROJECT_ID
Replace PROJECT_ID with the ID of your Cloud project. If
pom.xml file already
project ID, you don't need to include the
-Dapp.deploy.projectId property in the
command you run.
package goal builds and packages your app, and the
does the following:
Generates a unique version ID for the new version of your app.
Deploys the new version to App Engine.
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:
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,
For more information, see the
- Explore the plugin code and report issues on GitHub.
- Learn how to specify parameters for tasks by referring to App Engine Maven Goals and Parameters.