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 thepom.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.
Using the Google Cloud Client Libraries for Java
Google Cloud Client Libraries for Java provide idiomatic access to Google Cloud services. To use a library, declare it as a dependency.
Typically you only declare dependencies on the specific libraries that your function needs. For example:
Maven
Gradle
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.