From 726dbd28a0120a6541c14b8e94a1f0a8d808c02a Mon Sep 17 00:00:00 2001 From: Abhinand Sundararajan Date: Mon, 3 Nov 2025 17:08:23 +0530 Subject: [PATCH 1/3] feat: add run samples --- run/helloworld-source/README.md | 16 +++ run/helloworld-source/pom.xml | 97 +++++++++++++++++++ .../helloworld/HelloworldApplication.java | 45 +++++++++ .../src/main/resources/application.properties | 16 +++ .../HelloworldApplicationTests.java | 45 +++++++++ run/helloworld/pom.xml | 4 +- 6 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 run/helloworld-source/README.md create mode 100644 run/helloworld-source/pom.xml create mode 100644 run/helloworld-source/src/main/java/com/example/helloworld/HelloworldApplication.java create mode 100644 run/helloworld-source/src/main/resources/application.properties create mode 100644 run/helloworld-source/src/test/java/com/example/helloworld/HelloworldApplicationTests.java diff --git a/run/helloworld-source/README.md b/run/helloworld-source/README.md new file mode 100644 index 00000000000..0a0f4324b40 --- /dev/null +++ b/run/helloworld-source/README.md @@ -0,0 +1,16 @@ +# Cloud Run Hello World Sample + +This sample shows how to deploy a Hello World [Spring Boot](https://spring.io/projects/spring-boot) +application to Cloud Run using source deploy. + +For more details on how to work with this sample read the [Google Cloud Run Java Samples README](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/run). + +[![Run in Google Cloud][run_img]][run_link] + +[run_img]: https://storage.googleapis.com/cloudrun/button.svg +[run_link]: https://deploy.cloud.run/?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&dir=run/helloworld + +## Dependencies + +* **Spring Boot**: Web server framework. +* **Junit**: [development] Test running framework. diff --git a/run/helloworld-source/pom.xml b/run/helloworld-source/pom.xml new file mode 100644 index 00000000000..a14dae2cac7 --- /dev/null +++ b/run/helloworld-source/pom.xml @@ -0,0 +1,97 @@ + + + + 4.0.0 + com.example.run + helloworld-source + 0.0.1-SNAPSHOT + jar + + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + UTF-8 + UTF-8 + 25 + 25 + 3.5.6 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + test + + + junit + junit + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + com.google.cloud.tools + jib-maven-plugin + 3.4.0 + + + gcr.io/PROJECT_ID/helloworld + + + + + + + diff --git a/run/helloworld-source/src/main/java/com/example/helloworld/HelloworldApplication.java b/run/helloworld-source/src/main/java/com/example/helloworld/HelloworldApplication.java new file mode 100644 index 00000000000..c3165c9aca3 --- /dev/null +++ b/run/helloworld-source/src/main/java/com/example/helloworld/HelloworldApplication.java @@ -0,0 +1,45 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [START cloudrun_helloworld_service] + +package com.example.helloworld; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +public class HelloworldApplication { + + @Value("${NAME:World}") + String name; + + @RestController + class HelloworldController { + @GetMapping("/") + String hello() { + return "Hello " + name + "!"; + } + } + + public static void main(String[] args) { + SpringApplication.run(HelloworldApplication.class, args); + } +} +// [END cloudrun_helloworld_service] diff --git a/run/helloworld-source/src/main/resources/application.properties b/run/helloworld-source/src/main/resources/application.properties new file mode 100644 index 00000000000..3cebd9ca826 --- /dev/null +++ b/run/helloworld-source/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# [START cloudrun_helloworld_properties] +server.port=${PORT:8080} +# [END cloudrun_helloworld_properties] diff --git a/run/helloworld-source/src/test/java/com/example/helloworld/HelloworldApplicationTests.java b/run/helloworld-source/src/test/java/com/example/helloworld/HelloworldApplicationTests.java new file mode 100644 index 00000000000..c35e651b6bc --- /dev/null +++ b/run/helloworld-source/src/test/java/com/example/helloworld/HelloworldApplicationTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.helloworld; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class HelloworldApplicationTests { + + @Autowired private MockMvc mockMvc; + + @Test + public void returnsHelloWorld() throws Exception { + mockMvc + .perform(get("/")) + .andExpect(status().isOk()) + .andExpect(content().string("Hello World!")); + } +} diff --git a/run/helloworld/pom.xml b/run/helloworld/pom.xml index 70e213d033f..73c3ab340fa 100644 --- a/run/helloworld/pom.xml +++ b/run/helloworld/pom.xml @@ -41,8 +41,8 @@ limitations under the License. UTF-8 UTF-8 - 17 - 17 + 25 + 25 3.2.2 From c038f391e879f495017ddb81e8d0b00389b3517c Mon Sep 17 00:00:00 2001 From: Abhinand Sundararajan Date: Mon, 3 Nov 2025 17:57:41 +0530 Subject: [PATCH 2/3] Addressing review comments. --- run/helloworld-source/README.md | 2 +- run/helloworld/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/run/helloworld-source/README.md b/run/helloworld-source/README.md index 0a0f4324b40..635ed14952b 100644 --- a/run/helloworld-source/README.md +++ b/run/helloworld-source/README.md @@ -8,7 +8,7 @@ For more details on how to work with this sample read the [Google Cloud Run Java [![Run in Google Cloud][run_img]][run_link] [run_img]: https://storage.googleapis.com/cloudrun/button.svg -[run_link]: https://deploy.cloud.run/?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&dir=run/helloworld +[run_link]: https://deploy.cloud.run/?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&dir=run/helloworld-source ## Dependencies diff --git a/run/helloworld/pom.xml b/run/helloworld/pom.xml index 73c3ab340fa..775ed27ff94 100644 --- a/run/helloworld/pom.xml +++ b/run/helloworld/pom.xml @@ -43,7 +43,7 @@ limitations under the License. UTF-8 25 25 - 3.2.2 + 3.5.6 From 29f170f1dcf1d29c3961e561923ffb12f4024df3 Mon Sep 17 00:00:00 2001 From: Abhinand Sundararajan Date: Mon, 3 Nov 2025 21:06:55 +0530 Subject: [PATCH 3/3] Fixing Helloworld to Java21 for stability --- run/helloworld-source/pom.xml | 175 +++++++++++++++++++--------------- run/helloworld/pom.xml | 25 ++++- 2 files changed, 119 insertions(+), 81 deletions(-) diff --git a/run/helloworld-source/pom.xml b/run/helloworld-source/pom.xml index a14dae2cac7..069c0690c5a 100644 --- a/run/helloworld-source/pom.xml +++ b/run/helloworld-source/pom.xml @@ -12,86 +12,105 @@ See the License for the specific language governing permissions and limitations under the License. --> - 4.0.0 - com.example.run - helloworld-source - 0.0.1-SNAPSHOT - jar + 4.0.0 + com.example.run + helloworld + 0.0.1-SNAPSHOT + jar - + - - com.google.cloud.samples - shared-configuration - 1.2.0 - - + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + UTF-8 + UTF-8 + 21 + 21 + 3.2.2 + - - - org.springframework.boot - spring-boot-dependencies - ${spring-boot.version} - pom - import - + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + test + + + junit + junit + test + - - - UTF-8 - UTF-8 - 25 - 25 - 3.5.6 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - test - - - junit - junit - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot.version} - - - - repackage - - - - - - - com.google.cloud.tools - jib-maven-plugin - 3.4.0 - - - gcr.io/PROJECT_ID/helloworld - - - - - - + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + com.google.cloud.tools + jib-maven-plugin + 3.4.0 + + + gcr.io/PROJECT_ID/helloworld + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + diff --git a/run/helloworld/pom.xml b/run/helloworld/pom.xml index 775ed27ff94..59c54561f70 100644 --- a/run/helloworld/pom.xml +++ b/run/helloworld/pom.xml @@ -41,9 +41,9 @@ limitations under the License. UTF-8 UTF-8 - 25 - 25 - 3.5.6 + 21 + 21 + 3.2.2 @@ -92,6 +92,25 @@ limitations under the License. + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + + + prepare-agent + + + + report + prepare-package + + report + + + +