The Java runtime Stay organized with collections Save and categorize content based on your preferences.
Your Cloud Run function runs in an environment consisting of anoperating system version with add-on packages, language support, andtheJava Functions Frameworklibrary that supports and invokes your function. This environment is identifiedby the language version, and is known as the runtime ID.
Function preparation
You can prepare a function directly from the Google Cloud console or write it onyour local machine and upload it. To prepare your local machine for Javadevelopment, seeSet up a Java development environment.
Supported Java runtimes and base images
| Runtime | Runtime ID | Stacks | Runtime base image |
|---|---|---|---|
| Java 25 | java25 | ||
| Java 21 | java21 | ||
| Java 17 | java17 | ||
| Java 11 | java11 | google-18-full | google-18-full/java11 |
Select your runtime
You can select one of the supported Java runtimes for your function duringdeployment.
You can select a runtime version using the Google Cloud console, or thegcloud CLI. Click the tab for instructions on using the tool ofyour choice:
gcloud
Specify theJava base image for your function using the--base-image flag,while deploying your function. For example:
gcloud run deployFUNCTION \ --source . \ --functionFUNCTION_ENTRYPOINT \ --base-image java25Replace:
FUNCTION with the name of the function you aredeploying. You can omit this parameter entirely,but you will be prompted for the name if you omit it.
FUNCTION_ENTRYPOINT with the entry point to your function inyour source code. This is the code Cloud Run executes when yourfunction runs. The value of this flag must be a function name orfully-qualified class name that exists in your source code.
For detailed instructions on deploying a function using the gcloud CLI, seeDeploy functions in Cloud Run.
Console
You can select a runtime version when you create or update a Cloud Run function in the Google Cloud console. For detailedinstructions on deploying a function, seeDeploy functions in Cloud Run.
To select a runtime in the Google Cloud console when you create a function, follow these steps:
In the Google Cloud console, go to the Cloud Run page:
ClickWrite a function.
In theRuntime list, select a Java runtime version.
ClickCreate, and wait for Cloud Run to create the serviceusing a placeholder revision.
The console will redirect you to theSourcetab where you can see the source code of your function. ClickSave and redeploy.
For detailed instructions on updating the runtime version after your function isdeployed, seeRe-deploy new source code.
Source code structure
For Cloud Run functions to find your function's definition, yoursource code must follow a specific structure. SeeWrite Cloud Run functions formore information.
Specifying dependencies
You can specify dependencies for your function usingMavenorGradle. For more information, seeSpecifydependencies in Java.
Environment variables
Your Java runtime automatically sets certain environment variables for yourfunction to use as needed. For details, seeConfigure environmentvariables.
Execution ID
For Java functions that usefunctions-framework version 1.4.0 or later, youcan use the logging classjava.util.logging.Logger to add a unique executionID to log outputs. Usingstdout orstderr (for example,System.println()) does not add the execution ID.
Note that:
If you created your function using theCloud Functions v2 API(for example, by using
gcloud functions, the REST API, or Terraform), thisexecution ID is added automatically.If you created your function using theCloud Run Admin API(for example, by using Google Cloud console,
gcloud run, the REST API, orTerraform), you need to set theLOG_EXECUTION_IDenvironment variable totrueto use this feature.
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 2026-02-19 UTC.