If you are creating a new function, see the Console Quickstart on Cloud Run. The content on this page only applies to existing legacy functions created with the Cloud Functions v1 API.
Stay organized with collections
Save and categorize content based on your preferences.
Specify dependencies in Java
You can use any Java compatible libraries with a
supported Java runtime to write
Cloud Run functions in Java. You can use either
Maven or
Gradle to manage dependencies
for your Java Cloud Run functions.
Declaring and managing dependencies
You can declare and manage dependencies using either Maven or Gradle:
To manage dependencies using Maven:
Specify the dependencies in the <dependencies> section inside the
pom.xml
file of your project.
To manage your project's dependency on Maven itself, you can use the
Maven Wrapper. If you do not use the
Maven Wrapper, Cloud Run functions defaults to using a recent version of
Maven when running gcloud functions deploy.
To manage dependencies using Gradle, you specify the dependencies in the
build.gradle
file of your project.
The Functions Framework is a
required dependency for all functions. Although Cloud Run functions
installs it on your behalf when the function is created, we recommend
that you include it as an explicit dependency for clarity.
If your
function relies on private dependencies, we recommend that you
mirror functions-framework to your private registry. Include the mirrored
functions-framework as a dependency to your function to avoid installing the
package from the public internet.
Note that this build.gradle file includes a custom task to help you run
functions locally. For more discussion of local testing, see Your First
Function:
Java.
applyplugin:'java'repositories{jcenter()mavenCentral()}configurations{invoker}dependencies{// Every function needs this dependency to get the Functions Framework API.compileOnly'com.google.cloud.functions:functions-framework-api:1.1.0'// To run function locally using Functions Framework's local invokerinvoker'com.google.cloud.functions.invoker:java-function-invoker:1.3.1'// These dependencies are only used by the tests.testImplementation'com.google.cloud.functions:functions-framework-api:1.1.0'testImplementation'junit:junit:4.13.2'testImplementation'com.google.truth:truth:1.4.0'testImplementation'org.mockito:mockito-core:5.10.0'}// Register a "runFunction" task to run the function locallytasks.register("runFunction",JavaExec){main='com.google.cloud.functions.invoker.runner.Invoker'classpath(configurations.invoker)inputs.files(configurations.runtimeClasspath,sourceSets.main.output)args('--target',project.findProperty('run.functionTarget')?:'','--port',project.findProperty('run.port')?:8080)doFirst{args('--classpath',files(configurations.runtimeClasspath,sourceSets.main.output).asPath)}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-17 UTC."],[[["Java dependencies for Cloud Run functions can be managed using either Maven or Gradle."],["Maven dependencies are declared within the `\u003cdependencies\u003e` section of the `pom.xml` file, while Gradle dependencies are specified in the `build.gradle` file."],["The Functions Framework is a required dependency for all Cloud Run functions and is recommended to be explicitly included in your project dependencies."],["Google Cloud Client Libraries for Java can be used by declaring them as dependencies in either Maven or Gradle, allowing you to access Google Cloud services."],["Mirroring the function framework to a private registry is recommended if your function relies on private dependencies."]]],[]]