User Guide 2.+

November 24, 2022 ยท View on GitHub

Applying the Plugin

Apply the plugin following the instructions in README.md and using the appropriate plugin identifier:

  1. "com.google.cloud.tools.appengine-appenginewebxml" for war projects defined by an appengine-web.xml
  2. "com.google.cloud.tools.appengine-appyaml" for projects defined by an app.yaml
  3. "com.google.cloud.tools.appengine" for automatic environment determination (not recommended)

When you use the com.google.cloud.tools.appengine plugin it will automatically determine your environment based on the presence of an appengine-web.xml in src/main/webapp/WEB-INF/. It will enable appengine-appenginewebxml if present, appengine-appyaml otherwise. Note: autodetection will not work if you set a custom webAppDirName property of the war plugin. In this case, manually apply the right environment-specific plugin by specifying the corresponding plugin identifier as above.

The Cloud SDK will be downloaded automatically, unless cloudSdkHome property is provided (see tools section below).


App Engine appengine-web.xml based projects

Follow the instructions to apply the appengine-appenginewebxml plugin on the project

Tasks

The plugin exposes the following tasks :

Local Run

TaskDescription
appengineRunRun the application locally.
appengineStartStart the application in the background.
appengineStopStop a running application.

Deployment

TaskDescription
appengineStageStage an application for deployment.
appengineDeployDeploy an application.
appengineDeployCronDeploy cron configuration.
appengineDeployDispatchDeploy dispatch configuration.
appengineDeployDosDeploy dos configuration.
appengineDeployIndexDeploy datastore index configuration.
appengineDeployQueueDeploy queue configuration.

Other

TaskDescription
appengineCloudSdkLoginLaunch the Cloud SDK login webflow and set the global Cloud SDK auth state.
appengineShowConfigurationPrint out the plugin configuration.

Configuration

Once you've initialized gcloud you can run and deploy your application using the defaults provided by the plugin. To view the default configuration values, run :

$ ./gradlew appengineShowConfiguration

If you wish to customize the plugin further, the plugin can be configured using the appengine configuration closure.

appengine {
  tools {
    // configure the Cloud Sdk tooling
  }
  run {
    // configure local run
  }
  stage {
    // configure staging for deployment
  }
  deploy {
    // configure deployment
  }
}
Tools

The tools configuration has the following parameters :

ParameterDescription
serviceAccountKeyFileA Google project service account key file to run Cloud SDK operations requiring an authenticated user.
cloudSdkHomeLocation of the Cloud SDK.
cloudSdkVersionThe desired version of the Cloud SDK (e.g. "192.0.0").
verbosityThe verbosity level for logging when gcloud is run. See gcloud docs for allowed values.

The Cloud SDK will be installed/updated/verified depending on which parameters are configured:

Parameters SpecifiedAction
NoneLatest version of Cloud SDK is downloaded and installed.
Both parametersCloud SDK installation specified at cloudSdkHome is verified.
cloudSdkHome onlyNo verification.
cloudSdkVersion onlyCloud SDK at specified version is downloaded and installed.

The Cloud SDK is installed in $USER_HOME/.cache/google-cloud-tools-java/managed-cloud-sdk/<version>/google-cloud-sdk on Linux, $USER_HOME/Library/Application Support/google-cloud-tools-java/managed-cloud-sdk/<version>/google-cloud-sdk on OSX, and %LOCALAPPDATA%/google/ct4j-cloud-sdk/<version>/google-cloud-sdk on Windows. The Cloud SDK installation/verification occurs automatically before running any appengine tasks, but it can also be called explicitly by running the tasks downloadCloudSdk and checkCloudSdk.

Run

The run configuration has the following parameters :

ParameterDescription
environmentEnvironment variables to pass to the Dev App Server process
hostApplication host address.
jvmFlagsJVM flags to pass to the App Server Java process.
portApplication host port.
startSuccessTimeoutAmount of time in seconds to wait for the Dev App Server to start in the background.
servicesList of services to run
additionalArgumentsAdditional arguments to pass to the Dev App Server process
automaticRestartAutomatically restart the server when explode-war directory has changed
projectIdSet a Google Cloud Project Id on the running development server
Stage

The stage configuration has the following parameters :

ParameterDescription
compileEncodingThe character encoding to use when compiling JSPs.
deleteJspsDelete the JSP source files after compilation.
disableJarJspsDisable adding the classes generated from JSPs.
disableUpdateCheckDisable checking for App Engine SDK updates.
enableJarClassesJar the WEB-INF/classes content.
enableJarSplittingSplit JAR files larger than 10 MB into smaller fragments.
enableQuickstartUse Jetty quickstart to process servlet annotations.
jarSplittingExcludesExclude files that match the list of comma separated SUFFIXES from all JAR files.
sourceDirectoryThe location of the compiled web application files, or the exploded WAR. This is used as the source for staging.
stagingDirectoryThe directory to which to stage the application.
Deploy

The deploy configuration has the following parameters : Deploy has some extra parameters for app.yaml based projects that are not listed here and will just be ignored.

ParameterDescription
appEngineDirectoryLocation of configuration files (cron.yaml, dos.yaml, etc) for configuration specific deployments.
bucketThe Google Cloud Storage bucket used to stage files associated with the deployment.
gcloudModeThe gcloud preview mode (alpha, beta, etc) to use during deployments.
projectIdThe Google Cloud Project target for this deployment. This can also be set to GCLOUD_CONFIG.*
promotePromote the deployed version to receive all traffic.
serverThe App Engine server to connect to. Typically, you do not need to change this value.
stopPreviousVersionStop the previously running version of this service after deploying a new one that receives all traffic.
versionThe version of the app that will be created or replaced by this deployment. This also can be set to GCLOUD_CONFIG.*

* Setting a property to GCLOUD_CONFIG will deploy using the gcloud settings for the property.


How do I deploy my project Configuration Files?

You can now deploy index.yaml/dos.yaml/etc for all environments.

Use the following tasks :

  • appengineDeployCron
  • appengineDeployDispatch
  • appengineDeployDos
  • appengineDeployIndex
  • appengineDeployQueue

The deployment source directory can be overridden by setting the appEngineDirectory parameter in the deploy configuration.

For appengine-web.xml based projects, it defaults to ${buildDir}/staged-app/WEB-INF/appengine-generated. You should not change this configuration; this is the location that your xml configs are converted into yaml for deployment.

appengine {
  deploy {
    appEngineDirectory = "my/custom/appengine/project/configuration/directory"
  }
}

How do I debug Dev Appserver v1?

You can debug the Dev App Server v1 using the jvmFlags :

appengine {
  run {
    jvmFlags = ["-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"]
  }
}

How do I enable automatic reload of my application?

To enable automatic reload of your application:

  1. You must tell the Dev App Server v1 to scan for changes :
    appengine {
      run {
        automaticRestart = true
      }
    }
    
  2. While your app is running, just run explodeWar to copy the changes into the exploded app directly and reflect your changes into the running application.

If you wish to try gradle's experimental --continuous for automatic change application, see #174.

How do I put datastore somewhere else (so it's not deleted across rebuilds)?

appengine {
  run {
    jvmFlags = ["-Ddatastore.backing_store=/path/to/my/local_db.bin"]
  }
}

How do I run multiple modules on the Dev App Server v1?

Multimodule support can be done by adding all the runnable modules to a single runner's configuration (which currently must be an appengine-web.xml based application), and using a helper method to tie everything together.

appengine {
  run {
    // configure the app to point to the right service directories
    services = [
        projectAsService(project),
        projectAsService(":another-module")
    ]
  }
}

I want to use Dev Appserver 2 (alpha), how do I switch to it?

The v2-alpha Dev Appserver is no longer supported from this plugin.


App Engine app.yaml based projects

Follow the instructions to apply the appengine-appyaml plugin on the project

Tasks

The plugin exposes the following tasks :

Deployment

TaskDescription
appengineStageStage an application for deployment.
appengineDeployDeploy an application.
appengineDeployCronDeploy cron configuration.
appengineDeployDispatchDeploy dispatch configuration.
appengineDeployDosDeploy dos configuration.
appengineDeployIndexDeploy datastore index configuration.
appengineDeployQueueDeploy queue configuration.

Other

TaskDescription
appengineShowConfigurationPrint out the plugin configuration

Configuration

Once you've initialized gcloud you can deploy your application using the defaults provided by the plugin. To view the default configuration values, run :

$ ./gradlew appengineShowConfiguration

If you wish to customize the plugin further, the plugin can be configured using the appengine configuration closure.

appengine {
  tools {
    // configure the Cloud Sdk tooling
  }
  stage {
    // configure staging for deployment
  }
  deploy {
    // configure deployment
  }
}
Tools

The tools configuration has the following parameters :

ParameterDescription
serviceAccountKeyFileA Google project service account key file to run Cloud SDK operations requiring an authenticated user.
cloudSdkHomeLocation of the Cloud SDK.
cloudSdkVersionThe desired version of the Cloud SDK (e.g. "192.0.0").
verbosityThe verbosity level for logging when gcloud is run. See gcloud docs for allowed values.

The Cloud SDK will be installed/updated/verified depending on which parameters are configured:

Parameters SpecifiedAction
NoneLatest version of Cloud SDK is downloaded and installed.
Both parametersCloud SDK installation specified at cloudSdkHome is verified.
cloudSdkHome onlyNo verification.
cloudSdkVersion onlyCloud SDK at specified version is downloaded and installed.

The Cloud SDK is installed in $USER_HOME/.cache/google-cloud-tools-java/managed-cloud-sdk/<version>/google-cloud-sdk on Linux, $USER_HOME/Library/Application Support/google-cloud-tools-java/managed-cloud-sdk/<version>/google-cloud-sdk on OSX, and %LOCALAPPDATA%/google-cloud-tools-java/managed-cloud-sdk/<version>/google-cloud-sdk on Windows. The Cloud SDK installation/verification occurs automatically before running any appengine tasks, but it can also be called explicitly by running the tasks downloadCloudSdk and checkCloudSdk.

Stage

The stage configuration has the following parameters :

ParameterDescription
appEngineDirectoryThe directory that contains app.yaml.
dockerDirectoryThe directory that contains Dockerfile and other docker context.
artifactThe artifact to deploy (a file, like a .jar, a .war or a binary).
stagingDirectoryThe directory to which to stage the application.
extraFilesDirectoriesThe list of directories to copy extra files from.
Deploy

The deploy configuration has the following parameters :

ParameterDescription
appEngineDirectoryLocation of configuration files (cron.yaml, dos.yaml, etc) for configuration specific deployments.
bucketThe Google Cloud Storage bucket used to stage files associated with the deployment.
gcloudModeThe gcloud preview mode (alpha, beta, etc) to use during deployments.
imageUrlDeploy with a Docker URL from the Google container registry.
projectIdThe Google Cloud Project target for this deployment. This can also be set to GCLOUD_CONFIG.*
promotePromote the deployed version to receive all traffic.
serverThe App Engine server to connect to. Typically, you do not need to change this value.
stopPreviousVersionStop the previously running version of this service after deploying a new one that receives all traffic.
versionThe version of the app that will be created or replaced by this deployment. This also can be set to GCLOUD_CONFIG

* setting a property to GCLOUD_CONFIG will deploy using the gcloud settings for the property.