Skip to content

Commit 8982752

Browse files
authored
upgrade java project to spring boot 4.0 (#377)
1 parent b845ed7 commit 8982752

File tree

11 files changed

+131
-28
lines changed

11 files changed

+131
-28
lines changed

.devcontainer/java/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Java",
3-
"image": "mcr.microsoft.com/devcontainers/java:21-bullseye",
3+
"image": "mcr.microsoft.com/devcontainers/java:25-jdk-bookworm",
44
"containerEnv": {
55
"DISABLE_JAVA_BUILD": "true"
66
},

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ localstack/data
33
.mypy_cache
44
target
55
.idea
6-
postgres-data
6+
postgres-data
7+
.DS_Store

java/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Java Project
22

33
## Tech Stack
4-
- Java 21
5-
- JUnit 5
6-
- Spring Boot 3.2
4+
- Java 25
5+
- JUnit 6
6+
- Spring Boot 4.0
77
- Web
88
- JPA
99
- Lombok

java/build.gradle

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.2.0'
4-
id 'io.spring.dependency-management' version '1.1.4'
3+
id 'org.springframework.boot' version '4.0.0'
4+
id 'io.spring.dependency-management' version '1.1.7'
55
}
66

77
group = 'com.sourceallies'
88
version = '0.0.1-SNAPSHOT'
99

1010
java {
11-
sourceCompatibility = '21'
11+
toolchain {
12+
languageVersion = JavaLanguageVersion.of(25)
13+
}
1214
}
1315

1416
configurations {
@@ -23,17 +25,29 @@ repositories {
2325

2426
dependencies {
2527
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
26-
implementation 'org.springframework.boot:spring-boot-starter-web'
28+
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
2729
compileOnly 'org.projectlombok:lombok'
2830
runtimeOnly 'org.postgresql:postgresql'
2931
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
3032
annotationProcessor 'org.projectlombok:lombok'
31-
testImplementation 'org.springframework.boot:spring-boot-starter-test'
33+
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
34+
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
35+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3236
}
3337

3438
tasks.named('test') {
3539
useJUnitPlatform()
3640
testLogging {
37-
exceptionFormat "full"
41+
events = ["passed", "skipped", "failed"]
42+
exceptionFormat = "full"
43+
showExceptions = true
44+
showCauses = true
45+
showStackTraces = true
46+
}
47+
afterSuite { desc, result ->
48+
if (!desc.parent) {
49+
println "\nTest Results: ${result.resultType}"
50+
println "Tests run: ${result.testCount}, Passed: ${result.successfulTestCount}, Failed: ${result.failedTestCount}, Skipped: ${result.skippedTestCount}"
51+
}
3852
}
3953
}

java/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.configuration-cache=true
2.13 KB
Binary file not shown.

java/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

java/gradlew

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2021 the original authors.
4+
# Copyright © 2015 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
8890

8991
# Use the maximum available, or set MAX_FD != -1 to use that value.
9092
MAX_FD=maximum
@@ -112,7 +114,6 @@ case "$( uname )" in #(
112114
NONSTOP* ) nonstop=true ;;
113115
esac
114116

115-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116117

117118

118119
# Determine the Java command to use to start the JVM.
@@ -170,7 +171,6 @@ fi
170171
# For Cygwin or MSYS, switch paths to Windows format before running java
171172
if "$cygwin" || "$msys" ; then
172173
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173-
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174174

175175
JAVACMD=$( cygpath --unix "$JAVACMD" )
176176

@@ -203,15 +203,14 @@ fi
203203
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204204

205205
# Collect all arguments for the java command:
206-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207207
# and any embedded shellness will be escaped.
208208
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209209
# treated as '${Hostname}' itself on the command line.
210210

211211
set -- \
212212
"-Dorg.gradle.appname=$APP_BASE_NAME" \
213-
-classpath "$CLASSPATH" \
214-
org.gradle.wrapper.GradleWrapperMain \
213+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
215214
"$@"
216215

217216
# Stop when "xargs" is not available.

java/gradlew.bat

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
18+
19+
@if "%DEBUG%"=="" @echo off
20+
@rem ##########################################################################
21+
@rem
22+
@rem Gradle startup script for Windows
23+
@rem
24+
@rem ##########################################################################
25+
26+
@rem Set local scope for the variables with windows NT shell
27+
if "%OS%"=="Windows_NT" setlocal
28+
29+
set DIRNAME=%~dp0
30+
if "%DIRNAME%"=="" set DIRNAME=.
31+
@rem This is normally unused
32+
set APP_BASE_NAME=%~n0
33+
set APP_HOME=%DIRNAME%
34+
35+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
36+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37+
38+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40+
41+
@rem Find java.exe
42+
if defined JAVA_HOME goto findJavaFromJavaHome
43+
44+
set JAVA_EXE=java.exe
45+
%JAVA_EXE% -version >NUL 2>&1
46+
if %ERRORLEVEL% equ 0 goto execute
47+
48+
echo. 1>&2
49+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50+
echo. 1>&2
51+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52+
echo location of your Java installation. 1>&2
53+
54+
goto fail
55+
56+
:findJavaFromJavaHome
57+
set JAVA_HOME=%JAVA_HOME:"=%
58+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59+
60+
if exist "%JAVA_EXE%" goto execute
61+
62+
echo. 1>&2
63+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64+
echo. 1>&2
65+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66+
echo location of your Java installation. 1>&2
67+
68+
goto fail
69+
70+
:execute
71+
@rem Setup the command line
72+
73+
74+
75+
@rem Execute Gradle
76+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
77+
78+
:end
79+
@rem End local scope for the variables with windows NT shell
80+
if %ERRORLEVEL% equ 0 goto mainEnd
81+
82+
:fail
83+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
84+
rem the _cmd.exe /c_ return code!
85+
set EXIT_CODE=%ERRORLEVEL%
86+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
87+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
88+
exit /b %EXIT_CODE%
89+
90+
:mainEnd
91+
if "%OS%"=="Windows_NT" endlocal
92+
93+
:omega

java/src/main/java/com/sourceallies/interview/Solution.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.sourceallies.interview;
22

3-
import org.springframework.web.bind.annotation.GetMapping;
4-
import org.springframework.web.bind.annotation.RestController;
5-
6-
@RestController
73
public class Solution {
8-
9-
@GetMapping
4+
105
public String getGreeting() {
116
return "Hello, world!";
127
}

0 commit comments

Comments
 (0)