Documentation

Documentation versions (currently viewingVaadin 23)
New Acceleration Kits: Observability Kit, SSO Kit, and Swing Kit. Read the blog post.

Deploying a Vaadin Application to Google Cloud

Learn how to deploy your Vaadin application to Google Cloud.

This tutorial shows you how to deploy a Vaadin application to Google App Engine. Google Cloud has free-trial and free-tier offerings that you can read more about on the Google Cloud website.

Note
Google Cloud account required
To complete this tutorial, you need to sign up for a Google Cloud account at https://cloud.google.com/. Your Google Cloud account should also have the billing enabled.

Step 1: Install and Set Up Google Cloud SDK

To begin, download and install the Google Cloud SDK.

After it’s installed, run the following command from a terminal window to add App Engine support for Java to the SDK.

gcloud components install app-engine-java

Step 2: Download a Starter App

Download a minimal Vaadin project and unpack the downloaded zip into a folder on your computer.

Warning
Due to issue 14164, you need to disable the @PWA annotation found on the Application class.

Step 3: Initialize a Google Cloud Project

Open the project directory from a terminal window, and enter the following command to initialize a Google Cloud project:

gcloud init

If this is your first time running Google SDK, you’re asked to authenticate your account. When prompted to log in, enter 'Y' and allow the SDK to control your account in the opened browser window.

After authentication, you’re prompted to select a configuration. Enter '1' to select the default configuration, as in the following snippet:

Settings from your current configuration [default] are:
accessibility:
  screen_reader: 'False'
core:
  account: john.doe@gmail.com
  disable_usage_reporting: 'True'

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings
 [2] Create a new configuration
Please enter your numeric choice:  1

Step 4: Create an App Engine Instance

From a terminal window, in the project root directory, create a Google App Engine instance using the following command:

gcloud app create

You’re then be asked to select a region. You may want to choose the region that’s geographically closest to your users.

Step 5: Set Up the App Engine Plugin for Maven

Add the App Engine Maven plugin to your project’s pom.xml file.

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>2.4.3</version>
    <configuration>
        <projectId>GCLOUD_CONFIG</projectId>
        <version>GCLOUD_CONFIG</version>
    </configuration>
</plugin>

You need to set the projectId and version properties for the plugin to work. The value GCLOUD_CONFIG tells the Google Cloud CLI tools to use the projectId configured in step 4. Also, make sure to use the latest version of the appengine-maven-plugin, which you can find at this link.

Step 6: Create the app.yaml File

Next, you need to create an app.yaml file.

  1. Create a directory called appengine under src/main.

  2. Create a file called app.yaml under src/main/appengine. This file should have the following content.

    runtime: java11

    You should change the java runtime version number (java11) in the yaml file to match the value of the <java.version> property in your pom.xml file.

Step 7: Enable Cloud Build

You also need to enable Cloud Build.

  1. Navigate to https://console.cloud.google.com/cloud-build/builds?project=PROJECT_NAME, replacing PROJECT_NAME with your project name found at Google Cloud Resource Manager.

  2. Click Enable.

Step 8: Deploy to Google App Engine

Finally, you can build and deploy using a single command as follows:

mvn package appengine:deploy -Pproduction

When the deployment has finished, the application URL is displayed in the logs.

Common Problems

Ensure Google Cloud Billing is Enabled

If the deployment fails with an error similar to ERROR: (gcloud.app.deploy) Error Response: [7] Access Not Configured., then ensure that your Google Cloud account has billing enabled. After it’s enabled, try to deploy again.

Memory Limit

If you notice log messages similar to Exceeded soft memory limit of 256 MB with X MB, this means your instance has ran out of RAM. You should consider upgrading to a larger App Engine instance that fits your needs.

Warning
Be mindful of costs when upgrading. Larger instances most likely incur more fees.