Skip to content

Commit d39fb3f

Browse files
feat: migrate from Java 8 to Java 11
- Upgrade Spring Boot from 2.0.2.RELEASE to 2.7.18 (latest 2.x LTS) - Update pom.xml: java.version=11, maven.compiler.release=11, UTF-8 encoding - Add maven-compiler-plugin 3.11.0, surefire 3.2.5, failsafe 3.2.5, enforcer 3.5.0 - Add spring-boot-starter-test dependency for testing - Update build.gradle: JavaVersion.VERSION_11, Spring Boot plugin 2.7.18 - Replace deprecated compile/testCompile with implementation/testImplementation - Add integration tests: ApplicationTests, TopicControllerTest, TopicServiceTest - Add GitHub Actions CI workflow with JDK 11 (Temurin) - Add MIGRATION_NOTES.md documenting all changes - Update README.md with JDK 11 prerequisites and build/test instructions - Add @Profile to skip external API CommandLineRunner during tests Co-Authored-By: Lukas Burger <lukaskburger@gmail.com>
1 parent c31d0c6 commit d39fb3f

10 files changed

Lines changed: 409 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, 'devin/**' ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '11'
20+
distribution: 'temurin'
21+
cache: maven
22+
23+
- name: Build and verify with Maven
24+
run: mvn -B clean verify
25+
26+
- name: Run tests with Maven
27+
run: mvn -B test

MIGRATION_NOTES.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Migration Notes: Java 8 → Java 11
2+
3+
## Java Version Change
4+
5+
- **Source**: Java 8 (1.8)
6+
- **Target**: Java 11
7+
8+
Java 11 is a Long-Term Support (LTS) release that introduces improvements such as local-variable type inference (`var`), new String methods, HTTP Client API, and enhanced garbage collection. All existing Java 8 features (Streams, Lambdas, NIO, Optional, LocalDateTime) remain fully compatible.
9+
10+
## Spring Boot Version Upgrade
11+
12+
- **From**: Spring Boot 2.0.2.RELEASE
13+
- **To**: Spring Boot 2.7.18
14+
15+
Spring Boot 2.7.x is the final 2.x LTS line and provides full Java 11 support, along with security patches, dependency updates, and improved auto-configuration.
16+
17+
## Build Tool Changes
18+
19+
### Maven (`pom.xml`)
20+
21+
- `<java.version>` changed from `1.8` to `11`
22+
- Added `<maven.compiler.release>11</maven.compiler.release>`
23+
- Added `<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>`
24+
- Changed `<packaging>` from `pom` to `jar`
25+
- Spring Boot parent version updated to `2.7.18`
26+
27+
### Gradle (`build.gradle`)
28+
29+
- `sourceCompatibility` changed from `1.8` to `JavaVersion.VERSION_11`
30+
- `targetCompatibility` changed from `1.8` to `JavaVersion.VERSION_11`
31+
- Spring Boot Gradle plugin updated to `2.7.18`
32+
- Replaced deprecated `compile` configuration with `implementation`
33+
- Replaced deprecated `testCompile` configuration with `testImplementation`
34+
- Added `spring-boot-starter-jdbc` and `h2` dependencies to match Maven
35+
36+
## Plugin Upgrades
37+
38+
| Plugin | Version | Purpose |
39+
|--------|---------|---------|
40+
| `maven-compiler-plugin` | 3.11.0 | Compiles with `--release 11` flag |
41+
| `maven-surefire-plugin` | 3.2.5 | Runs unit tests |
42+
| `maven-failsafe-plugin` | 3.2.5 | Runs integration tests |
43+
| `maven-enforcer-plugin` | 3.5.0 | Enforces minimum Java 11 at build time |
44+
45+
## New Test Coverage
46+
47+
- **`ApplicationTests.java`**: Spring Boot integration test verifying the application context loads successfully.
48+
- **`TopicControllerTest.java`**: MockMvc-based tests for all REST endpoints (`GET /topic`, `POST /topic`, `PUT /topic/{id}`, `DELETE /topic/{id}`, `GET /`, `GET /datetime`, etc.).
49+
- **`TopicServiceTest.java`**: Unit tests for service-layer methods covering Stream operations, NIO file methods, String processing, sorting, and filtering.
50+
51+
## CI Workflow Added
52+
53+
A GitHub Actions CI workflow (`.github/workflows/ci.yml`) was added:
54+
- Triggers on push and pull request to `main`
55+
- Uses `actions/setup-java@v4` with Temurin JDK 11
56+
- Caches Maven dependencies
57+
- Runs `mvn -B clean verify` and `mvn -B test`

README.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# springboot-java8
2-
The project is made on spring boot. The project summarize the new features present in Java 8.
2+
The project is made on spring Boot. The project summarize the new features present in Java 8.
33
It contain list of harcoded topics list. You can call the apis's with POSTMAN to add,delete,update Topic list
44
In addition, it uses
55
1) Java 8 NIO methods
@@ -18,7 +18,41 @@ In addition, it uses
1818

1919
## Getting Started
2020
1) Download or clone the project with link
21-
(https://github.com/RehmanMuradAli/springboot-java8/)
21+
(https://github.com/COG-GTM/springboot-java8)
22+
23+
## Prerequisites
24+
25+
- **JDK 11** or later
26+
- **Maven 3.6+** or **Gradle 6+**
27+
- **POSTMAN** (optional, for API testing)
28+
29+
## Build & Run
30+
31+
### With Maven
32+
```bash
33+
mvn clean package
34+
mvn spring-boot:run
35+
```
36+
37+
### With Gradle
38+
```bash
39+
./gradlew build
40+
./gradlew bootRun
41+
```
42+
43+
The application starts on `http://localhost:8080` by default.
44+
45+
## Running Tests
46+
47+
### With Maven
48+
```bash
49+
mvn clean test
50+
```
51+
52+
### With Gradle
53+
```bash
54+
./gradlew test
55+
```
2256

2357
## Available API's
2458

@@ -74,23 +108,6 @@ GET /datetime
74108

75109

76110

77-
### Prerequisites
78-
79-
1) Java sdk
80-
2) POSTMAN
81-
82-
### Installing
83-
84-
85-
86-
```
87-
1) Download or clone
88-
2) Import the project
89-
3) Run on location machine
90-
4) Open Postman, to call API's ( localhost:8080 )
91-
```
92-
93-
94111
## Helpful Links
95112
Spring:
96113

@@ -130,5 +147,3 @@ https://dzone.com/articles/java-8-friday-goodies-new-new
130147
## Authors
131148

132149
* **Rehman Murad Ali**
133-
134-

build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
6+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
77
}
88
}
99

@@ -22,11 +22,12 @@ repositories {
2222
mavenCentral()
2323
}
2424

25-
sourceCompatibility = 1.8
26-
targetCompatibility = 1.8
25+
sourceCompatibility = JavaVersion.VERSION_11
26+
targetCompatibility = JavaVersion.VERSION_11
2727

2828
dependencies {
29-
compile("org.springframework.boot:spring-boot-starter-web")
30-
testCompile("junit:junit")
29+
implementation("org.springframework.boot:spring-boot-starter-web")
30+
implementation("org.springframework.boot:spring-boot-starter-jdbc")
31+
implementation("com.h2database:h2")
32+
testImplementation("org.springframework.boot:spring-boot-starter-test")
3133
}
32-

pom.xml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
<groupId>org.springframework</groupId>
77
<artifactId>gs-spring-boot</artifactId>
8-
<packaging>pom</packaging>
8+
<packaging>jar</packaging>
99
<version>0.1.0</version>
1010

1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>2.0.2.RELEASE</version>
14+
<version>2.7.18</version>
1515
</parent>
1616

1717
<dependencies>
@@ -32,19 +32,63 @@
3232
<groupId>com.h2database</groupId>
3333
<artifactId>h2</artifactId>
3434
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-test</artifactId>
38+
<scope>test</scope>
39+
</dependency>
3540
</dependencies>
3641

3742
<properties>
38-
<java.version>1.8</java.version>
43+
<java.version>11</java.version>
44+
<maven.compiler.release>11</maven.compiler.release>
45+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3946
</properties>
4047

41-
4248
<build>
4349
<plugins>
4450
<plugin>
4551
<groupId>org.springframework.boot</groupId>
4652
<artifactId>spring-boot-maven-plugin</artifactId>
4753
</plugin>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>3.11.0</version>
58+
<configuration>
59+
<release>11</release>
60+
</configuration>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-surefire-plugin</artifactId>
65+
<version>3.2.5</version>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-failsafe-plugin</artifactId>
70+
<version>3.2.5</version>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-enforcer-plugin</artifactId>
75+
<version>3.5.0</version>
76+
<executions>
77+
<execution>
78+
<id>enforce-java</id>
79+
<goals>
80+
<goal>enforce</goal>
81+
</goals>
82+
<configuration>
83+
<rules>
84+
<requireJavaVersion>
85+
<version>[11,)</version>
86+
</requireJavaVersion>
87+
</rules>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
4892
</plugins>
4993
</build>
5094

src/main/java/hello/Application.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) {
4747
}
4848

4949
@Bean
50+
@org.springframework.context.annotation.Profile("!test")
5051
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
5152
return args -> {
5253
Quote quote = restTemplate.getForObject(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package hello;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class ApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
}

0 commit comments

Comments
 (0)