Skip to content

Commit 970a2d5

Browse files
authored
chore: update gradle function (GoogleCloudPlatform#7154)
1 parent c9049ae commit 970a2d5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

functions/helloworld/hello-http-gradle/build.gradle

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ repositories {
2020
mavenCentral()
2121
}
2222

23+
configurations {
24+
invoker
25+
}
26+
2327
dependencies {
2428
// Every function needs this dependency to get the Functions Framework API.
25-
compileOnly 'com.google.cloud.functions:functions-framework-api:1.0.4'
29+
implementation 'com.google.cloud.functions:functions-framework-api:1.0.4'
30+
invoker 'com.google.cloud.functions.invoker:java-function-invoker:1.1.0'
2631

2732
// Function implementations can have additional dependencies like this.
2833
implementation 'com.google.code.gson:gson:2.8.8'
@@ -39,4 +44,19 @@ jar {
3944
// There must be a jar {} section, though the archiveBaseName does not have to be 'function'.
4045
archiveBaseName = 'function'
4146
}
47+
48+
// Run your function locally:
49+
// ./gradlew runFunction -Prun.functionTarget=functions.HelloHttp -Prun.port=8080
50+
tasks.register("runFunction", JavaExec) {
51+
main = 'com.google.cloud.functions.invoker.runner.Invoker'
52+
classpath(configurations.invoker)
53+
inputs.files(configurations.runtimeClasspath, sourceSets.main.output)
54+
args(
55+
'--target', project.findProperty('run.functionTarget'),
56+
'--port', project.findProperty('run.port') ?: 8080
57+
)
58+
doFirst {
59+
args('--classpath', files(configurations.runtimeClasspath, sourceSets.main.output).asPath)
60+
}
61+
}
4262
// [END functions_build_gradle]

0 commit comments

Comments
 (0)