Use Gradle and the App Engine plugin Stay organized with collections Save and categorize content based on your preferences.
Gradle is an open-source build automation tool focused on flexibility and performance.App Engine provides a Gradle plugin that you can use to build and deployyour app to App Engine.Note: For information about other ways to build and deploy your app, seeTesting and deploying your app. If you haven't already done so, follow the steps in thisguideto download the gcloud CLI, create your Google Cloud project, andinitialize your App Engine app. Install the gcloud CLI You can create a new Gradle project from scratch using the shell. Alternatively,to try out the plugin, you can download, run locally, and deploythe hello world project. To create a new project: Create a new directory and navigate to it. To initialize a new project: Run You'll be asked to answer questions: Create the Create the Remove the stub files generated by Add the following to your You also need to add the following files to your project, using a texteditor or integrated development environment (IDE): SeeSet up your development environment for anoverview of a Java App Engine project. To access Google resources from your project when running locally,set the application default credentials by running: Change to the root of your application directory. During the development phase, you can run and test your application at anytime in the development server by invoking Gradle: Alternatively, you can run Gradle without installing it byusing the Gradle wrapper. Wait for the server to start. The server is started with yourapplication running when you see a message similar to this: See your app running at To learn more about theGretty plugin,seeGretty Configuration andGretty tasks. To deploy your application: The Gradle provides a mechanism to download and run the required version of Gradlewithout installation: Change to the sample code directory. Run gradlew: Change to the sample code directory. Run gradlew: Additional information on Gradle can be found inApp Engine Gradle Tasks and Properties.Before you begin
app-engine-java component:gcloudcomponentsinstallapp-engine-javaCreate a new Gradle project
gradle init:gradleinit--typejava-applicationWEB-INF folder:mkdir-papp/src/main/webapp/WEB-INFappengine folder:mkdir-papp/src/main/appenginegradle init:rm./app/src/main/java/org/example/App.java./app/src/test/java/org/example/AppTest.javaapp/build.gradle file to add App EngineGradle tasks, Maven repositories, the App Engine Gradle plugin,dependencies, and task configuration:applyplugin:'java'applyplugin:'war'buildscript{repositories{// gretty plugin is in Maven CentralmavenCentral()}dependencies{classpath'com.google.cloud.tools:appengine-gradle-plugin:2.8.1'classpath'org.gretty:gretty:4.1.5'}}applyplugin:'org.gretty'applyplugin:'com.google.cloud.tools.appengine'repositories{mavenCentral()}appengine{deploy{// deploy configurationstopPreviousVersion=true// default - stop the current versionpromote=true// default - & make this the current versionprojectId='GCLOUD_CONFIG'version='GCLOUD_CONFIG'}}sourceSets{// In Gradle 8, the default location is app/src/java, which does not match// Maven's directory structure.main.java.srcDirs=['src/main/java']main.resources.srcDirs=['src/main/resources','src/main/webapp']test.java.srcDirs=['src/test/java']}dependencies{implementation'com.google.appengine:appengine-api-1.0-sdk:2.0.30'implementation'jakarta.servlet:jakarta.servlet-api:6.1.0'// Test DependenciestestImplementation'com.google.appengine:appengine-testing:2.0.30'testImplementation'com.google.appengine:appengine-api-stubs:2.0.30'testImplementation'com.google.appengine:appengine-tools-sdk:2.0.30'testImplementation'com.google.truth:truth:1.1.5'testImplementation'junit:junit:4.13.2'testImplementation'org.mockito:mockito-core:4.11.0'}Testing your application with the development server
gcloudauthapplication-defaultlogingradlejettyRun:prepareInplaceWebAppFolder:createInplaceWebAppFolder:compileJava:processResources UP-TO-DATE:classes:prepareInplaceWebAppClasses:prepareInplaceWebApp:jettyRun17:40:05 INFO Jetty 9.2.15.v20160210 started and listening on port 808017:40:05 INFO runs at:17:40:05 INFO http://localhost:8080/
http://localhost:8080.Deploy your application
gradleappengineDeployappengineDeploy task and all other Gradle tasks have associated propertiesthat you can use. For a complete list of tasks and properties, refer toApp Engine Gradle Tasks and Properties.Use the Gradle wrapper
Linux/macOS
./gradlewjettyRunWindows
./gradlew.batjettyRunWhat's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.