지원되는 Java 런타임으로 모든 Java 호환 라이브러리를 사용하여 Java에서 Cloud Run Functions를 작성할 수 있습니다. Maven 또는 Gradle을 사용하여 Java Cloud Run Functions에 대해 종속 항목을 관리할 수 있습니다.
종속 항목 선언 및 관리
Maven 또는 Gradle을 사용하여 종속 항목을 선언 및 관리할 수 있습니다.
Maven을 사용하여 종속 항목을 관리하려면 다음 안내를 따르세요.
프로젝트의 pom.xml 파일 내에서 <dependencies> 섹션에 종속 항목을 지정합니다.
Maven 자체에서 프로젝트 종속 항목을 관리하려면 Maven 래퍼를 사용할 수 있습니다. Maven 래퍼를 사용하지 않는 경우 Cloud Run Functions에는 gcloud functions deploy를 실행할 때 기본적으로 Maven의 최신 버전이 사용됩니다.
Gradle을 사용하여 종속 항목을 관리하려면 프로젝트의 build.gradle 파일에 종속 항목을 지정합니다.
함수 프레임워크는 모든 함수에 필요한 종속 항목입니다. Cloud Run Functions는 함수 생성 시 이를 자동으로 설치하지만 명확히 하자면 명시적 종속 항목으로 포함하는 것이 좋습니다.
함수에서 비공개 종속 항목을 사용하는 경우 functions-framework를 비공개 레지스트리에 미러링하는 것이 좋습니다. 공개 인터넷에서 패키지를 설치하지 않으려면 미러링된 functions-framework를 함수에 대한 종속 항목으로 포함합니다.
이 build.gradle 파일에는 함수를 로컬로 실행하는 데 도움이 되는 커스텀 작업이 포함되어 있습니다. 로컬 테스트에 대한 자세한 내용은 첫 번째 함수: 자바를 참조하세요.
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)}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-03(UTC)"],[[["\u003cp\u003eJava dependencies for Cloud Run functions can be managed using either Maven or Gradle.\u003c/p\u003e\n"],["\u003cp\u003eMaven dependencies are declared within the \u003ccode\u003e<dependencies>\u003c/code\u003e section of the \u003ccode\u003epom.xml\u003c/code\u003e file, while Gradle dependencies are specified in the \u003ccode\u003ebuild.gradle\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe Functions Framework is a required dependency for all Cloud Run functions and is recommended to be explicitly included in your project dependencies.\u003c/p\u003e\n"],["\u003cp\u003eGoogle 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.\u003c/p\u003e\n"],["\u003cp\u003eMirroring the function framework to a private registry is recommended if your function relies on private dependencies.\u003c/p\u003e\n"]]],[],null,["# Specify dependencies in Java\n============================\n\nYou can use any Java compatible libraries with a\n[supported Java runtime](/functions/1stgendocs/runtime-support#java) to write\nCloud Run functions in Java. You can use either\n[Maven](https://maven.apache.org/) or\n[Gradle](https://gradle.org/) to manage dependencies\nfor your Java Cloud Run functions.\n\nDeclaring and managing dependencies\n-----------------------------------\n\nYou can declare and manage dependencies using either Maven or Gradle:\n\n- To manage dependencies using Maven:\n\n - Specify the dependencies in the `\u003cdependencies\u003e` section inside the\n [`pom.xml`](http://maven.apache.org/guides/introduction/introduction-to-the-pom.html)\n file of your project.\n\n - To manage your project's dependency on Maven itself, you can use the\n [Maven Wrapper](https://maven.apache.org/wrapper/). If you do not use the\n Maven Wrapper, Cloud Run functions defaults to using a recent version of\n Maven when running [`gcloud functions deploy`](//sdk/gcloud/reference/functions/deploy).\n\n- To manage dependencies using Gradle, you specify the dependencies in the\n [`build.gradle`](https://docs.gradle.org/current/userguide/tutorial_using_tasks.html)\n file of your project.\n\nThe [Functions Framework](/functions/docs/functions-framework) is a\nrequired dependency for all functions. Although Cloud Run functions\ninstalls it on your behalf when the function is created, we recommend\nthat you include it as an explicit dependency for clarity.\n\nIf your\nfunction relies on private dependencies, we recommend that you\nmirror `functions-framework` to your private registry. Include the mirrored\n`functions-framework` as a dependency to your function to avoid installing the\npackage from the public internet.\n\nUsing the Google Cloud Client Libraries for Java\n------------------------------------------------\n\n[Google Cloud Client Libraries for\nJava](https://github.com/googleapis/google-cloud-java) provide idiomatic access\nto Google Cloud services. To use a library, declare it as a dependency.\n\nTypically you only declare dependencies on the specific libraries that your\nfunction needs. For example: \n\n### Maven\n\n \u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n\n \u003cgroupId\u003ecom.example.functions\u003c/groupId\u003e\n \u003cartifactId\u003efunctions-hello-world\u003c/artifactId\u003e\n \u003cversion\u003e1.0.0-SNAPSHOT\u003c/version\u003e\n \u003cproperties\u003e\n \u003cmaven.compiler.target\u003e11\u003c/maven.compiler.target\u003e\n \u003cmaven.compiler.source\u003e11\u003c/maven.compiler.source\u003e\n \u003c/properties\u003e\n\n \u003cdependencies\u003e\n \u003c!-- Required for Function primitives --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.cloud.functions\u003c/groupId\u003e\n \u003cartifactId\u003efunctions-framework-api\u003c/artifactId\u003e\n \u003cversion\u003e1.1.0\u003c/version\u003e\n \u003cscope\u003eprovided\u003c/scope\u003e\n \u003c/dependency\u003e\n \u003c/dependencies\u003e\n\n \u003cbuild\u003e\n \u003cplugins\u003e\n \u003cplugin\u003e\n \u003c!--\n Google Cloud Functions Framework Maven plugin\n\n This plugin allows you to run Cloud Functions Java code\n locally. Use the following terminal command to run a\n given function locally:\n\n mvn function:run -Drun.functionTarget=your.package.yourFunction\n --\u003e\n \u003cgroupId\u003ecom.google.cloud.functions\u003c/groupId\u003e\n \u003cartifactId\u003efunction-maven-plugin\u003c/artifactId\u003e\n \u003cversion\u003e0.11.0\u003c/version\u003e\n \u003cconfiguration\u003e\n \u003cfunctionTarget\u003efunctions.HelloWorld\u003c/functionTarget\u003e\n \u003c/configuration\u003e\n \u003c/plugin\u003e\n \u003c/plugins\u003e\n \u003c/build\u003e\n \u003c/project\u003e\n\n### Gradle\n\nNote that this `build.gradle` file includes a custom task to help you run\nfunctions locally. For more discussion of local testing, see [Your First\nFunction:\nJava](/functions/1stgendocs/create-deploy-http-java-1st-gen#building_and_testing_locally). \n\n apply plugin: 'java'\n\n repositories {\n jcenter()\n mavenCentral()\n }\n configurations {\n invoker\n }\n\n dependencies {\n // Every function needs this dependency to get the Functions Framework API.\n compileOnly 'com.google.cloud.functions:functions-framework-api:1.1.0'\n\n // To run function locally using Functions Framework's local invoker\n invoker 'com.google.cloud.functions.invoker:java-function-invoker:1.3.1'\n\n // These dependencies are only used by the tests.\n testImplementation 'com.google.cloud.functions:functions-framework-api:1.1.0'\n testImplementation 'junit:junit:4.13.2'\n testImplementation 'com.google.truth:truth:1.4.0'\n testImplementation 'org.mockito:mockito-core:5.10.0'\n\n }\n\n // Register a \"runFunction\" task to run the function locally\n tasks.register(\"runFunction\", JavaExec) {\n main = 'com.google.cloud.functions.invoker.runner.Invoker'\n classpath(configurations.invoker)\n inputs.files(configurations.runtimeClasspath, sourceSets.main.output)\n args(\n '--target', project.findProperty('run.functionTarget') ?: '',\n '--port', project.findProperty('run.port') ?: 8080\n )\n doFirst {\n args('--classpath', files(configurations.runtimeClasspath, sourceSets.main.output).asPath)\n }\n }"]]