Skip to content

Commit 3a767e0

Browse files
build(maven): target Java 11 via release; upgrade plugins and deps
- maven-compiler-plugin 3.1 → 3.11.0 with <release>11</release> - Add maven-surefire-plugin 3.2.5, maven-enforcer-plugin 3.5.0 - JMH 1.17.4 → 1.37, JUnit 4.11 → 4.13.2 - Fix deprecated new Double(String) → Double.parseDouble() - Add GitHub Actions CI workflow for JDK 11 - Add MIGRATION_NOTES.md, update README.md for JDK 11 - Update .gitignore to allow .github directory Co-Authored-By: derek.wu <derekwu35@gmail.com>
1 parent 4786c46 commit 3a767e0

6 files changed

Lines changed: 110 additions & 16 deletions

File tree

.github/workflows/java11-build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Java 11 Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Setup JDK 11
11+
uses: actions/setup-java@v4
12+
with:
13+
distribution: temurin
14+
java-version: '11'
15+
cache: maven
16+
- name: Compile
17+
run: mvn -B -e clean compile
18+
- name: Package (includes JMH shade)
19+
run: mvn -B -e -DskipTests package

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Eclipse, Netbeans and IntelliJ files
55
/.*
66
!.gitignore
7+
!.github
78
/nbproject
89
/*.ipr
910
/*.iws

MIGRATION_NOTES.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Java 9 → 11 Migration Notes
2+
3+
## Summary
4+
5+
This project has been migrated from Java 9 (`source`/`target` 1.9) to **Java 11 (LTS)** using the `release` compiler flag. The migration is minimal and behavior-safe, targeting build and dependency compatibility.
6+
7+
## Build Changes
8+
9+
### Maven Compiler Plugin
10+
- **Before**: `maven-compiler-plugin` 3.1 with `<source>1.9</source>` / `<target>1.9</target>`
11+
- **After**: `maven-compiler-plugin` 3.11.0 with `<release>11</release>`
12+
13+
### New Plugins
14+
- `maven-surefire-plugin` 3.2.5 — modern test runner compatible with Java 11+
15+
- `maven-enforcer-plugin` 3.5.0 — enforces JDK 11 as the minimum build version
16+
17+
### Dependency Upgrades
18+
| Dependency | Old Version | New Version | Reason |
19+
|---|---|---|---|
20+
| JMH (core + annprocess) | 1.17.4 | 1.37 | Java 11 compatibility |
21+
| JUnit | 4.11 | 4.13.2 | Security fixes, Java 11 support |
22+
23+
## Code Changes
24+
25+
- `Util.java`: Replaced `new Double(String)` (deprecated since Java 9, marked for removal) with `Double.parseDouble(String)`.
26+
27+
## Removed JDK Modules
28+
29+
No removed JDK modules (JAXB, JAX-WS, CORBA, JavaFX, Nashorn) were in use — no replacement dependencies needed.
30+
31+
## Encapsulation / JPMS
32+
33+
The project runs on the **classpath** (no `module-info.java`). No illegal reflective access warnings are present.
34+
35+
## Known Warnings (Intentional)
36+
37+
- `DateTimeExamples.java` uses the deprecated `Date(int, int, int)` constructor — this is intentional for the educational example contrasting old and new Date/Time APIs.
38+
- `StreamForker.java` uses unchecked/unsafe operations — inherent to the generics example.
39+
40+
## CI
41+
42+
A GitHub Actions workflow (`.github/workflows/java11-build.yml`) has been added to build and compile on JDK 11 (Temurin).
43+
44+
## GC / Logging
45+
46+
No JVM flags or GC options were configured in this project. The default G1 collector in Java 11 applies.
47+
48+
## TLS / Security
49+
50+
No TLS endpoints, keystores, or cipher configurations exist in this codebase.
51+
52+
## Follow-ups
53+
54+
- Consider adopting `var` (Java 10) for local type inference in examples.
55+
- Consider adding `java.net.http.HttpClient` (Java 11) usage examples.
56+
- Consider adding test classes under `src/test/java/`.

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ The source code for all examples can be found in the directory [src/main/java/la
2929
* Appendix D: Lambdas and JVM bytecode
3030
We will update the repository as we update the book. Stay tuned!
3131

32-
### Make sure to have JDK8 installed
33-
The latest binary can be found here: http://www.oracle.com/technetwork/java/javase/overview/java8-2100321.html
32+
### Requirements: JDK 11+
33+
Install [Eclipse Temurin 11](https://adoptium.net/temurin/releases/?version=11) (or any JDK 11+ distribution).
3434

35-
$ java -version
35+
$ java -version
36+
openjdk version "11.0.x" ...
3637

37-
java version "1.8.0_05"
38-
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
39-
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
40-
41-
42-
You can download a preview version here: https://jdk8.java.net/
38+
See [MIGRATION_NOTES.md](MIGRATION_NOTES.md) for details on the Java 9 → 11 migration.
4339

4440
### Compile/Run the examples
4541
Using maven:

pom.xml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@
99
<version>1.0</version>
1010

1111
<properties>
12+
<maven.compiler.release>11</maven.compiler.release>
1213
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1314
</properties>
1415

1516
<dependencies>
1617
<dependency>
1718
<groupId>org.openjdk.jmh</groupId>
1819
<artifactId>jmh-core</artifactId>
19-
<version>1.17.4</version>
20+
<version>1.37</version>
2021
</dependency>
2122
<dependency>
2223
<groupId>org.openjdk.jmh</groupId>
2324
<artifactId>jmh-generator-annprocess</artifactId>
24-
<version>1.17.4</version>
25+
<version>1.37</version>
2526
</dependency>
2627
<dependency>
2728
<groupId>junit</groupId>
2829
<artifactId>junit</artifactId>
29-
<version>4.11</version>
30+
<version>4.13.2</version>
3031
</dependency>
3132
</dependencies>
3233

@@ -35,12 +36,33 @@
3536
<plugin>
3637
<groupId>org.apache.maven.plugins</groupId>
3738
<artifactId>maven-compiler-plugin</artifactId>
38-
<version>3.1</version>
39+
<version>3.11.0</version>
3940
<configuration>
40-
<source>1.9</source>
41-
<target>1.9</target>
41+
<release>11</release>
4242
</configuration>
4343
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>3.2.5</version>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-enforcer-plugin</artifactId>
52+
<version>3.5.0</version>
53+
<executions>
54+
<execution>
55+
<goals><goal>enforce</goal></goals>
56+
<configuration>
57+
<rules>
58+
<requireJavaVersion>
59+
<version>[11,)</version>
60+
</requireJavaVersion>
61+
</rules>
62+
</configuration>
63+
</execution>
64+
</executions>
65+
</plugin>
4466
<plugin>
4567
<groupId>org.apache.maven.plugins</groupId>
4668
<artifactId>maven-shade-plugin</artifactId>

src/main/java/lambdasinaction/chap11/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void delay() {
2525

2626
public static double format(double number) {
2727
synchronized (formatter) {
28-
return new Double(formatter.format(number));
28+
return Double.parseDouble(formatter.format(number));
2929
}
3030
}
3131

0 commit comments

Comments
 (0)