Skip to content

Commit 05f029d

Browse files
committed
Add Maven 4 migrations for three initial examples
This commit implements Maven 4 migrations for the first three examples, validating the migration strategy across different module patterns. **Migrated Examples:** 1. **example_hiddenmain/m4/** - Single module (modmain) - Demonstrates non-exported main classes concept - Two main class executions in run.sh - Tests: Single-module migration pattern 2. **example_requires-static/m4/** - Three modules (modmain, modb, modc) - Demonstrates optional compile-time dependencies (requires static) - Special runtime flags: --add-modules modb,modc - Tests: Multi-module with optional dependencies 3. **example_requires_exports/m4/** - Three modules (modmain, modb, modc) - Demonstrates basic requires/exports (fundamental JPMS concept) - Standard dependency chain: modmain → modb → modc - Tests: Multi-module with standard dependencies **Each m4/ Directory Structure:** - pom.xml: Maven 4.1.0 with Module Source Hierarchy approach - modelVersion: 4.1.0 - maven-compiler-plugin: 4.0.0-beta-3 - maven.compiler.release: 11 (targets Java 11 bytecode) - Explicit <sources> declarations for each module - Scripts (all shellcheck-compliant): - compile.sh: Maven 4 compile + traditional jar packaging - run.sh: Execution preserving original JVM flags - verify.sh: Golden master testing integration (--only flag support) - clean.sh: Artifact cleanup - Source structure: - src/java/{module}/main → ../../../../src/{module} (symlinks) - Follows Maven 4 Module Source Hierarchy pattern - .gitignore: Excludes target/, mlib/, run-result/ **Build Configuration:** - Maven execution: JDK 17 (JAVA17_HOME) - Compilation target: Java 11 via --release 11 flag - Runtime: JDK 11 (JAVA_HOME) - Build isolation: m4/mlib/ separate from ../mlib/ **Extended documentation:** Add a new "Maven 4 Output" section to the documentation of each result. **Verification Results:** All migrations verified with golden master testing: ✅ example_hiddenmain/m4 - Bytecode: major version 55 (Java 11) - Output matches expected result ✅ example_requires-static/m4 - Bytecode: major version 55 (Java 11) - Output matches expected result ✅ example_requires_exports/m4 - Bytecode: major version 55 (Java 11) - Output matches expected result This validates the migration strategy works across: - Single-module and multi-module projects - Different JPMS features (requires static, requires/exports) - Various runtime configurations (multiple mains, special flags) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Introduced in the course of support-and-care/maven-support-and-care#137
1 parent ea7926c commit 05f029d

File tree

29 files changed

+543
-1
lines changed

29 files changed

+543
-1
lines changed

.claude/transformations/maven-4-migration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,21 @@ EOF
574574
./verify.sh
575575
```
576576

577-
10. **Document Issues**: Note any JPMS/Maven plugin compatibility issues for future resolution
577+
10. **Update Example README**: Add Maven 4 output section to the example's README.adoc:
578+
```adoc
579+
==== Maven 4 Output
580+
581+
This example has been migrated to Maven 4 using the Module Source Hierarchy layout.
582+
The Maven 4 build is located in the `m4/` subdirectory and produces identical output:
583+
584+
[source]
585+
----
586+
include::m4/run-result/run.txt[]
587+
----
588+
```
589+
This documents the migration completion and shows that Maven 4 produces equivalent output.
590+
591+
11. **Document Issues**: Note any JPMS/Maven plugin compatibility issues for future resolution
578592

579593
### Example Selection Criteria
580594

jigsaw-examples/example_hiddenmain/README.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ include::expected-result/run.txt[]
5555
----
5656
include::run-result/run.txt[]
5757
----
58+
59+
==== Maven 4 Output
60+
61+
This example has been migrated to Maven 4 using the Module Source Hierarchy layout.
62+
The Maven 4 build is located in the `m4/` subdirectory and produces identical output:
63+
64+
[source]
65+
----
66+
include::m4/run-result/run.txt[]
67+
----
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
mlib/
3+
run-result/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
rm -rf target
3+
rm -rf mlib
4+
rm -rf run-result
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
# shellcheck source=../../env.sh
5+
source ../../env.sh
6+
7+
# Ensure we're using Maven 4
8+
if [ -z "${M4_HOME:-}" ]; then
9+
echo "ERROR: M4_HOME is not set. Please configure it in .envrc or env.sh"
10+
exit 1
11+
fi
12+
13+
# Maven 4 requires Java 17+ to run
14+
# Note: pom.xml has <maven.compiler.release>11</maven.compiler.release> which ensures
15+
# Java 11 compatible bytecode even when using JDK 17 compiler with --release 11
16+
if [ -n "${JAVA17_HOME:-}" ]; then
17+
export JAVA_HOME="${JAVA17_HOME}"
18+
fi
19+
20+
# Add Maven 4 to PATH
21+
export PATH="${M4_HOME}/bin:${PATH}"
22+
23+
mkdir -p mlib
24+
25+
echo "mvn --version"
26+
mvn --version
27+
echo
28+
29+
echo "mvn clean compile"
30+
echo "(Maven runs with JDK 17, compiles for Java 11 via maven.compiler.release)"
31+
mvn clean compile
32+
33+
# Create JARs directly to mlib (similar to original compile.sh)
34+
pushd target/classes > /dev/null 2>&1
35+
for dir in */;
36+
do
37+
MODDIR=${dir%*/}
38+
echo "jar $JAR_OPTIONS --create --file=../../mlib/${MODDIR}.jar -C ${MODDIR} ."
39+
# shellcheck disable=SC2086 # JAR_OPTIONS is intentionally unquoted for word splitting
40+
"${JAVA_HOME}/bin/jar" $JAR_OPTIONS --create --file="../../mlib/${MODDIR}.jar" -C "${MODDIR}" . 2>&1
41+
done
42+
popd >/dev/null 2>&1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.1.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0
5+
http://maven.apache.org/xsd/maven-4.1.0.xsd">
6+
<modelVersion>4.1.0</modelVersion>
7+
8+
<groupId>com.example.jigsaw</groupId>
9+
<artifactId>example-hiddenmain-m4</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<properties>
13+
<maven.compiler.release>11</maven.compiler.release>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<build>
18+
<sources>
19+
<source>
20+
<module>modmain</module>
21+
<directory>src/java/modmain/main</directory>
22+
</source>
23+
</sources>
24+
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>4.0.0-beta-3</version>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
# shellcheck source=../../env.sh
5+
source ../../env.sh
6+
7+
# Show Java version for user information
8+
echo "Using Java version:"
9+
"${JAVA_HOME}/bin/java" -version
10+
echo
11+
12+
# Create run-result directory if it doesn't exist
13+
mkdir -p run-result
14+
15+
# Run the first Java command, save output to run-result/run.txt, and display with highlighting
16+
# shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting
17+
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
18+
19+
# Run the second Java command, append output to run-result/run.txt, and display with highlighting
20+
# shellcheck disable=SC2086 # JAVA_OPTIONS is intentionally unquoted for word splitting
21+
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmainhidden.HiddenMain 2>&1 | normalize | tee -a run-result/run.txt | myecho
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../src/modmain
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
EXAMPLE_NAME="$(basename "$(dirname "$(pwd)")")"
5+
EXPECTED="../expected-result/run.txt"
6+
ACTUAL="run-result/run.txt"
7+
8+
# Parse command line arguments
9+
ONLY_VERIFY=false
10+
if [ "${1:-}" = "--only" ]; then
11+
ONLY_VERIFY=true
12+
fi
13+
14+
echo "=== Verifying ${EXAMPLE_NAME} (Maven 4) ==="
15+
echo
16+
17+
# Check if expected result exists
18+
if [ ! -f "${EXPECTED}" ]; then
19+
echo "❌ ERROR: Expected result not found at ${EXPECTED}"
20+
echo " Run ../create-expected-result.sh first to create the golden master"
21+
exit 1
22+
fi
23+
24+
# Perform full build unless --only is specified
25+
if [ "${ONLY_VERIFY}" = false ]; then
26+
echo "Step 1: Compile"
27+
./compile.sh
28+
echo
29+
30+
echo "Step 2: Run and capture output"
31+
./run.sh
32+
echo
33+
else
34+
echo "Skipping compile (--only mode)"
35+
echo
36+
37+
# Check if actual result exists
38+
if [ ! -f "${ACTUAL}" ]; then
39+
echo "❌ ERROR: Actual result not found at ${ACTUAL}"
40+
echo " Run ./run.sh first to generate the actual output"
41+
exit 1
42+
fi
43+
fi
44+
45+
# Compare the files
46+
echo "Step 3: Compare expected vs actual output"
47+
if diff -u "${EXPECTED}" "${ACTUAL}"; then
48+
echo
49+
echo "✅ SUCCESS: Output matches expected result"
50+
exit 0
51+
else
52+
echo
53+
echo "❌ FAILURE: Output differs from expected result"
54+
echo " Expected: ${EXPECTED}"
55+
echo " Actual: ${ACTUAL}"
56+
exit 1
57+
fi

jigsaw-examples/example_requires-static/README.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,13 @@ include::expected-result/run.txt[]
5454
----
5555
include::run-result/run.txt[]
5656
----
57+
58+
==== Maven 4 Output
59+
60+
This example has been migrated to Maven 4 using the Module Source Hierarchy layout.
61+
The Maven 4 build is located in the `m4/` subdirectory and produces identical output:
62+
63+
[source]
64+
----
65+
include::m4/run-result/run.txt[]
66+
----

0 commit comments

Comments
 (0)