Skip to content

Commit 386279a

Browse files
committed
Update to maven-jar-plugin PR #508 snapshot
Update all m4/pom.xml to use maven-jar-plugin 4.0.0-beta-2-PR508-SNAPSHOT which provides automatic JAR-per-module creation. Additional changes: - Convert example_addExports_manifest/m4/src/modmain from symlink to real directory to support MANIFEST.MF with Add-Exports and Main-Class - Add Maven 4 Migration Notes to example_addExports_manifest/README.adoc - Document resource handling in README.adoc Dependencies: - apache/maven-jar-plugin#508: Automatic JAR-per-module creation - apache/maven#11505: Module-aware resource copying 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Introduced in the course of support-and-care/maven-support-and-care#137
1 parent 46fee74 commit 386279a

File tree

42 files changed

+134
-1359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+134
-1359
lines changed

README.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,13 @@ Examples requiring specific JDK versions may need `fork` and `executable` config
388388
Examples requiring specific JDK versions may need `fork` and `executable` configuration with environment-specific paths.
389389

390390
Resource handling::
391-
Examples with non-.class resources (like xref:jigsaw-examples/example_resources/README.adoc#maven-4-migration[example_resources]) need `maven-resources-plugin` configuration to copy resources from the modular source directories (`src/<module>/main`) to the target classes directories, as the hybrid compilation approach only packages compiled `.class` files by default.
391+
Examples with non-.class resources (like xref:jigsaw-examples/example_resources/README.adoc#maven-4-migration[example_resources]) need resources copied from the modular source directories (`src/<module>/main/resources`) to the target classes directories (`target/classes/<module>/`).
392+
+
393+
With https://github.com/apache/maven/pull/11505[Maven Core PR #11505], this happens automatically - the resources plugin discovers resources from the modular layout and copies them to the correct location.
394+
+
395+
Special case: xref:jigsaw-examples/example_addExports_manifest/README.adoc#sec:maven-4-migration[example_addExports_manifest] requires a custom `MANIFEST.MF` in `src/modmain/main/resources/META-INF/`.
396+
This example uses real source directories (not symlinks) because the `MANIFEST.MF` must be copied alongside the Java sources.
397+
See the example's README for detailed migration notes.
392398

393399
Multiple module versions::
394400
Examples requiring multiple versions of the same module (like xref:jigsaw-examples/example_layer-modules-module-resolution/README.adoc#maven-4-migration[example_layer-modules-module-resolution]) cannot use the standard Module Source Hierarchy approach, as the `<sources>` element expects one source location per module name.

jigsaw-examples/example_addExports_manifest/README.adoc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,53 @@ include::run-result/run.txt[]
8484
----
8585
include::m4/run-result/run.txt[]
8686
----
87+
88+
=== Maven 4 Migration Notes
89+
90+
This example requires special handling for Maven 4 migration due to the `MANIFEST.MF` file that must be included in the JAR.
91+
92+
==== Directory Structure
93+
94+
Unlike most other examples that use symlinks from `m4/src/<module>/main/java` to the original sources, this example uses a real directory structure for `modmain`:
95+
96+
[source]
97+
----
98+
m4/src/modmain/main/
99+
├── java/
100+
│ ├── module-info.java
101+
│ └── pkgmain/
102+
│ └── Main.java
103+
└── resources/
104+
└── META-INF/
105+
└── MANIFEST.MF
106+
----
107+
108+
The `moda` module still uses a symlink since it doesn't require resources.
109+
110+
==== MANIFEST.MF Content
111+
112+
The `MANIFEST.MF` contains custom entries that are merged with the JAR tool's default manifest:
113+
114+
[source]
115+
----
116+
Add-Exports: java.base/jdk.internal.misc moda/pkgainternal
117+
Main-Class: pkgmain.Main
118+
----
119+
120+
[NOTE]
121+
====
122+
The standard `Manifest-Version` and `Created-By` entries are omitted from the source `MANIFEST.MF` because they are automatically added by the JAR tool.
123+
Including them would cause duplicate entry warnings.
124+
====
125+
126+
==== Required Maven PRs
127+
128+
This example depends on two Maven improvements:
129+
130+
. https://github.com/apache/maven/pull/11505[Maven Core PR #11505]: Automatic module-aware resource handling
131+
** Automatically discovers resources from `src/<module>/main/resources`
132+
** Copies them to `target/classes/<module>/`
133+
134+
. https://github.com/apache/maven-jar-plugin/pull/508[JAR Plugin PR #508]: Automatic JAR-per-module creation
135+
** Creates individual JARs for each module (e.g., `modmain-1.0-SNAPSHOT.jar`)
136+
** Reads `Main-Class` from the module's `MANIFEST.MF` in `target/classes/<module>/META-INF/`

jigsaw-examples/example_addExports_manifest/m4/pom.xml

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</sources>
2727

2828
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-resources-plugin</artifactId>
32+
<version>3.3.1</version>
33+
</plugin>
2934
<plugin>
3035
<groupId>org.apache.maven.plugins</groupId>
3136
<artifactId>maven-compiler-plugin</artifactId>
@@ -46,40 +51,7 @@
4651
<plugin>
4752
<groupId>org.apache.maven.plugins</groupId>
4853
<artifactId>maven-jar-plugin</artifactId>
49-
<version>3.4.2</version>
50-
<executions>
51-
<!-- Skip default JAR creation -->
52-
<execution>
53-
<id>default-jar</id>
54-
<phase>none</phase>
55-
</execution>
56-
<!-- Create module-specific JARs -->
57-
<execution>
58-
<id>moda</id>
59-
<phase>package</phase>
60-
<goals>
61-
<goal>jar</goal>
62-
</goals>
63-
<configuration>
64-
<classesDirectory>${project.build.outputDirectory}/moda</classesDirectory>
65-
<classifier>moda</classifier>
66-
</configuration>
67-
</execution>
68-
<execution>
69-
<id>modmain</id>
70-
<phase>package</phase>
71-
<goals>
72-
<goal>jar</goal>
73-
</goals>
74-
<configuration>
75-
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
76-
<classifier>modmain</classifier>
77-
<archive>
78-
<manifestFile>src/modmain/main/java/META-INF/MANIFEST.MF</manifestFile>
79-
</archive>
80-
</configuration>
81-
</execution>
82-
</executions>
54+
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
8355
</plugin>
8456
</plugins>
8557
</build>

jigsaw-examples/example_addExports_manifest/m4/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ mkdir -p run-result
3030
"${JAVA11_HOME}/bin/java" ${JAVA_OPTIONS} \
3131
--add-modules moda \
3232
--module-path target \
33-
-jar target/example_addExports_manifest-m4-1.0-SNAPSHOT-modmain.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho
33+
-jar target/modmain-1.0-SNAPSHOT.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho

jigsaw-examples/example_addExports_manifest/m4/src/modmain/main/java

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
open module modmain { // allow reflective access, currently used in the example_jerry-mouse
2+
requires moda;
3+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pkgmain;
2+
3+
import jdk.internal.misc.SharedSecrets;
4+
5+
/**
6+
* This class cannot be compiled in Eclipse as compiler options --add-exports are needed.
7+
* See compile.sh for details.
8+
*
9+
* But if compilation has taken place outside Eclipse with the script,
10+
* the modular JARs can be found in .../mlib
11+
*
12+
* The Eclipse launch files takes the compiled code from there and can be run in Eclipse.
13+
*/
14+
15+
public class Main {
16+
public static void main(String[] args) {
17+
// Compiler and also Runtime option needed: --add-exports java.base/jdk.internal.misc=modmain
18+
SharedSecrets secrets = new SharedSecrets();
19+
System.out.println("Do you want to know a secret: " + secrets.getClass().getName());
20+
21+
// Compiler and also Runtime option needed: --add-exports moda/pkgainternal=modmain
22+
System.out.println(new pkgainternal.A().doIt());
23+
}
24+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add-Exports: java.base/jdk.internal.misc moda/pkgainternal
2+
Main-Class: pkgmain.Main

jigsaw-examples/example_addReads_addExports/m4/pom.xml

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,7 @@
4949
<plugin>
5050
<groupId>org.apache.maven.plugins</groupId>
5151
<artifactId>maven-jar-plugin</artifactId>
52-
<version>3.4.2</version>
53-
<executions>
54-
<!-- Skip default JAR creation -->
55-
<execution>
56-
<id>default-jar</id>
57-
<phase>none</phase>
58-
</execution>
59-
<!-- Create module-specific JARs -->
60-
<execution>
61-
<id>modb</id>
62-
<phase>package</phase>
63-
<goals>
64-
<goal>jar</goal>
65-
</goals>
66-
<configuration>
67-
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
68-
<classifier>modb</classifier>
69-
</configuration>
70-
</execution>
71-
<execution>
72-
<id>modc</id>
73-
<phase>package</phase>
74-
<goals>
75-
<goal>jar</goal>
76-
</goals>
77-
<configuration>
78-
<classesDirectory>${project.build.outputDirectory}/modc</classesDirectory>
79-
<classifier>modc</classifier>
80-
</configuration>
81-
</execution>
82-
<execution>
83-
<id>modmain</id>
84-
<phase>package</phase>
85-
<goals>
86-
<goal>jar</goal>
87-
</goals>
88-
<configuration>
89-
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
90-
<classifier>modmain</classifier>
91-
</configuration>
92-
</execution>
93-
</executions>
52+
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
9453
</plugin>
9554
</plugins>
9655
</build>

jigsaw-examples/example_addReads_addExports_reflection/m4/pom.xml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,7 @@
4242
<plugin>
4343
<groupId>org.apache.maven.plugins</groupId>
4444
<artifactId>maven-jar-plugin</artifactId>
45-
<version>3.4.2</version>
46-
<executions>
47-
<!-- Skip default JAR creation -->
48-
<execution>
49-
<id>default-jar</id>
50-
<phase>none</phase>
51-
</execution>
52-
<!-- Create module-specific JARs -->
53-
<execution>
54-
<id>modb</id>
55-
<phase>package</phase>
56-
<goals>
57-
<goal>jar</goal>
58-
</goals>
59-
<configuration>
60-
<classesDirectory>${project.build.outputDirectory}/modb</classesDirectory>
61-
<classifier>modb</classifier>
62-
</configuration>
63-
</execution>
64-
<execution>
65-
<id>modmain</id>
66-
<phase>package</phase>
67-
<goals>
68-
<goal>jar</goal>
69-
</goals>
70-
<configuration>
71-
<classesDirectory>${project.build.outputDirectory}/modmain</classesDirectory>
72-
<classifier>modmain</classifier>
73-
</configuration>
74-
</execution>
75-
</executions>
45+
<version>4.0.0-beta-2-PR508-SNAPSHOT</version>
7646
</plugin>
7747
</plugins>
7848
</build>

0 commit comments

Comments
 (0)