This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new fdf2ad80b0 fix: load JLine on module-path for targeted
--enable-native-access (fixes #11028) (#13491)
fdf2ad80b0 is described below
commit fdf2ad80b036daa4f93adef6a80a9a1189f98605
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 6 15:36:43 2026 +0100
fix: load JLine on module-path for targeted --enable-native-access (fixes
#11028) (#13491)
* fix: load JLine on module-path for targeted --enable-native-access (fixes
#11028)
- component.xml: move JLine JARs to lib/modules/, exclude from lib/
- m2.conf: add 'module' directives for JLine JARs + classpath fallback
- mvn: replace --enable-native-access=ALL-UNNAMED with targeted module-path
probe; fall back to ALL-UNNAMED when lib/modules/ is unavailable or JDK
does not support the flag; use boot/*.jar wildcard (no longer tied to
plexus-classworlds filename)
- mvn.cmd: same targeted native-access; use IS_MAIN_OVERRIDE to suppress
MAVEN_ARGS for sub-commands (--enc, --shell, --up, --val)
- component.xml: drop outputFileNameMapping shim — boot/*.jar wildcard in
the launcher scripts makes the filename opaque, so maven-classworlds can
now be deployed under its natural name
- LICENSE.vm: update JLine license block to lib/modules directory
- MavenCli.java (compat): add explicit (ClassRealm) cast after API change
* fix: add missing MAVEN_VERSION_PRINTED to mvn.cmd debug echo
---
apache-maven/src/assembly/component.xml | 14 +++++++----
apache-maven/src/assembly/maven/bin/m2.conf | 7 ++++++
apache-maven/src/assembly/maven/bin/mvn | 20 +++++++++++++---
apache-maven/src/assembly/maven/bin/mvn.cmd | 28 +++++++++++++++++-----
.../main/appended-resources/META-INF/LICENSE.vm | 8 +++++--
.../main/java/org/apache/maven/cli/MavenCli.java | 2 +-
6 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/apache-maven/src/assembly/component.xml
b/apache-maven/src/assembly/component.xml
index 84f3bda039..edaacbf6f6 100644
--- a/apache-maven/src/assembly/component.xml
+++ b/apache-maven/src/assembly/component.xml
@@ -25,16 +25,22 @@ under the License.
<includes>
<include>org.apache.maven:maven-classworlds</include>
</includes>
- <!-- Preserve the legacy plexus-classworlds-*.jar file name for backward
compatibility:
- wrapper scripts, CI tooling, and IDEs that glob
boot/plexus-classworlds-*.jar continue
- to work without change after the internalization. -->
-
<outputFileNameMapping>plexus-classworlds-${artifact.version}.jar</outputFileNameMapping>
</dependencySet>
+
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <outputDirectory>lib/modules</outputDirectory>
+ <includes>
+ <include>org.jline:*</include>
+ </includes>
+ </dependencySet>
+
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>org.apache.maven:maven-classworlds</exclude>
+ <exclude>org.jline:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
diff --git a/apache-maven/src/assembly/maven/bin/m2.conf
b/apache-maven/src/assembly/maven/bin/m2.conf
index e1ec455bcf..83c70ab1c1 100644
--- a/apache-maven/src/assembly/maven/bin/m2.conf
+++ b/apache-maven/src/assembly/maven/bin/m2.conf
@@ -21,6 +21,8 @@ main is org.apache.maven.cling.MavenCling from plexus.core
set maven.conf default ${maven.home}/conf
set maven.installation.conf default ${maven.conf}
+module ${maven.home}/lib/modules/*.jar
+
[plexus.core]
load ${maven.conf}/logging
optionally ${maven.home}/lib/ext/redisson/*.jar
@@ -29,3 +31,8 @@ optionally ${user.home}/.m2/ext/*.jar
optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/maven-*.jar
load ${maven.home}/lib/*.jar
+# The `load` below is a classpath fallback for embedders and older JDKs where
+# createModuleLayer() is not invoked. When the module layer IS created, these
+# entries are shadowed by the parent ModuleLayer loader (ParentFirstStrategy),
+# so there is no functional duplication in the normal case.
+load ${maven.home}/lib/modules/*.jar
diff --git a/apache-maven/src/assembly/maven/bin/mvn
b/apache-maven/src/assembly/maven/bin/mvn
index b6444540eb..a42b1719e5 100755
--- a/apache-maven/src/assembly/maven/bin/mvn
+++ b/apache-maven/src/assembly/maven/bin/mvn
@@ -485,20 +485,34 @@ fi
if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
printf '[DEBUG] Final MAVEN_OPTS: %s\n' "$MAVEN_OPTS" >&2
fi
-LAUNCHER_JAR=`echo "$MAVEN_HOME"/boot/plexus-classworlds-*.jar`
+LAUNCHER_JAR=""
+for _jar in "$MAVEN_HOME"/boot/*.jar; do
+ [ -f "$_jar" ] && LAUNCHER_JAR="${LAUNCHER_JAR:+$LAUNCHER_JAR:}$_jar"
+done
LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
JLINE_NATIVE_PATH="$MAVEN_HOME/lib/jline-native"
+MODULES_DIR="$MAVEN_HOME/lib/modules"
# For Cygwin and MinGW, switch paths to Windows format before running java(1)
command
if $cygwin || $mingw ; then
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
- LAUNCHER_JAR=`cygpath --windows "$LAUNCHER_JAR"`
+ LAUNCHER_JAR=`cygpath --windows --path "$LAUNCHER_JAR"`
CLASSWORLDS_CONF=`cygpath --windows "$CLASSWORLDS_CONF"`
MAVEN_HOME=`cygpath --windows "$MAVEN_HOME"`
# converted separately, appending to the already converted MAVEN_HOME would
# produce a path mixing both separators, e.g. C:\maven/lib/jline-native
JLINE_NATIVE_PATH=`cygpath --windows "$JLINE_NATIVE_PATH"`
+ MODULES_DIR=`cygpath --windows "$MODULES_DIR"`
+fi
+
+# Module-path and native access flags require a JDK that can read the module
jars.
+# The probe includes --module-path so it fails on JDKs that cannot read the
module descriptors.
+# Fall back to ALL-UNNAMED so that --enable-native-access is always granted on
JDK 22+,
+# even when the module-path probe fails (older JDK, missing lib/modules/,
locked-down env).
+MAVEN_MODULE_OPTS="--enable-native-access=ALL-UNNAMED"
+if "$JAVACMD" --module-path "$MODULES_DIR" --add-modules ALL-MODULE-PATH
--enable-native-access=org.jline.terminal.ffm -version >/dev/null 2>&1; then
+ MAVEN_MODULE_OPTS="--module-path \"$MODULES_DIR\" --add-modules
ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm,org.jline.nativ"
fi
MAVEN_PROJECTBASEDIR="$MAVEN_PROJECTBASEDIR_NATIVE"
@@ -581,7 +595,7 @@
MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}
cmd="\"$JAVACMD\" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
- --enable-native-access=ALL-UNNAMED \
+ $MAVEN_MODULE_OPTS \
-classpath \"$LAUNCHER_JAR\" \
\"-Dclassworlds.conf=$CLASSWORLDS_CONF\" \
\"-Dmaven.home=$MAVEN_HOME\" \
diff --git a/apache-maven/src/assembly/maven/bin/mvn.cmd
b/apache-maven/src/assembly/maven/bin/mvn.cmd
index c399d4a0b7..3cdd42a275 100644
--- a/apache-maven/src/assembly/maven/bin/mvn.cmd
+++ b/apache-maven/src/assembly/maven/bin/mvn.cmd
@@ -390,17 +390,33 @@ goto processArgs
:endHandleArgs
call :processArgs %*
-for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do set LAUNCHER_JAR="%%i"
+set LAUNCHER_JAR="%MAVEN_HOME%\boot\*"
set LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
+set MODULES_DIR="%MAVEN_HOME%\lib\modules"
if "%MAVEN_MAIN_CLASS%"=="" @set
MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenCling
-@REM Only pass MAVEN_ARGS for the default Maven build command (MavenCling),
+@rem Module-path and native access flags require a JDK that can read the
module jars.
+@rem The probe includes --module-path so it fails on JDKs that cannot read the
module descriptors.
+@rem Fall back to ALL-UNNAMED so that --enable-native-access is always granted
on JDK 22+,
+@rem even when the module-path probe fails (older JDK, missing lib\modules\,
locked-down env).
+set MAVEN_MODULE_OPTS=--enable-native-access=ALL-UNNAMED
+"%JAVACMD%" --module-path %MODULES_DIR% --add-modules ALL-MODULE-PATH
--enable-native-access=org.jline.terminal.ffm -version >NUL 2>&1
+if not ERRORLEVEL 1 (
+ set MAVEN_MODULE_OPTS=--module-path %MODULES_DIR% --add-modules
ALL-MODULE-PATH --enable-native-access=org.jline.terminal.ffm,org.jline.nativ
+)
+
+@REM MAVEN_ARGS is only passed for the default Maven build command
(MavenCling),
@REM not for sub-commands like --up, --enc, --shell or --val which have their
own options.
-if not "%MAVEN_MAIN_CLASS%"=="org.apache.maven.cling.MavenCling" set
"MAVEN_ARGS="
+@REM IS_MAIN_OVERRIDE is set during argument scanning when any of those flags
is found.
+if defined IS_MAIN_OVERRIDE (
+ set "MAVEN_EFFECTIVE_ARGS="
+) else (
+ set "MAVEN_EFFECTIVE_ARGS=%MAVEN_ARGS%"
+)
if defined MAVEN_DEBUG_SCRIPT (
echo [DEBUG] Launching JVM with command:
- echo [DEBUG] "%JAVACMD%" %INTERNAL_MAVEN_OPTS% %MAVEN_OPTS%
%JVM_CONFIG_ARGFILE_ARG% %MAVEN_DEBUG_OPTS% --enable-native-access=ALL-UNNAMED
-classpath %LAUNCHER_JAR% "-Dclassworlds.conf=%CLASSWORLDS_CONF%"
"-Dmaven.home=%MAVEN_HOME%" "-Dmaven.mainClass=%MAVEN_MAIN_CLASS%"
"-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native"
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%"
%MAVEN_VERSION_PRINTED% %LAUNCHER_CLASS% %MAVEN_ARGS% %*
+ echo [DEBUG] "%JAVACMD%" %INTERNAL_MAVEN_OPTS% %MAVEN_OPTS%
%JVM_CONFIG_ARGFILE_ARG% %MAVEN_DEBUG_OPTS% %MAVEN_MODULE_OPTS% -classpath
%LAUNCHER_JAR% "-Dclassworlds.conf=%CLASSWORLDS_CONF%"
"-Dmaven.home=%MAVEN_HOME%" "-Dmaven.mainClass=%MAVEN_MAIN_CLASS%"
"-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native"
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%"
%MAVEN_VERSION_PRINTED% %LAUNCHER_CLASS% %MAVEN_EFFECTIVE_ARGS% %*
)
"%JAVACMD%" ^
@@ -408,7 +424,7 @@ if defined MAVEN_DEBUG_SCRIPT (
%MAVEN_OPTS% ^
%JVM_CONFIG_ARGFILE_ARG% ^
%MAVEN_DEBUG_OPTS% ^
- --enable-native-access=ALL-UNNAMED ^
+ %MAVEN_MODULE_OPTS% ^
-classpath %LAUNCHER_JAR% ^
"-Dclassworlds.conf=%CLASSWORLDS_CONF%" ^
"-Dmaven.home=%MAVEN_HOME%" ^
@@ -417,7 +433,7 @@ if defined MAVEN_DEBUG_SCRIPT (
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%MAVEN_VERSION_PRINTED% ^
%LAUNCHER_CLASS% ^
- %MAVEN_ARGS% ^
+ %MAVEN_EFFECTIVE_ARGS% ^
%*
set JVM_CONFIG_EXIT_CODE=%ERRORLEVEL%
rem Cleanup the jvm.config temp directory now that the JVM has exited (must be
before @endlocal)
diff --git a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm
b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm
index af50f94620..03bf90436c 100644
--- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm
+++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm
@@ -271,10 +271,14 @@ subject to the terms and conditions of the following
licenses:
#* *##set ( $project.url = 'https://github.com/google/guice/' ) ##
#* *##end ##
#* *###
-#* *### Classworlds is in boot directory, not in lib
-#* *##if ( $project.artifact.artifactId == "plexus-classworlds" )
+#* *### Classworlds and its API are in boot directory, not in lib
+#* *##if ( $project.artifact.artifactId == "maven-classworlds" ||
$project.artifact.artifactId == "maven-api-classworlds" )
#* *##set ( $directory = 'boot' ) ##
#* *##end ##
+#* *### JLine modules are in lib/modules directory
+#* *##if ( $groupId == "org.jline" )
+#* *##set ( $directory = 'lib/modules' ) ##
+#* *##end ##
#* *###
#* *### copy license file to lib/$artifactId.license
#* *##set ( $licFile = $directory + '/' + $project.artifact.artifactId +
'.license' ) ##
diff --git
a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 99269ec987..4f3b641282 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -973,7 +973,7 @@ private ClassRealm setupContainerRealm(
for (CoreExtensionEntry entry : reverse(extensions)) {
Set<String> exportedPackages = entry.getExportedPackages();
- ClassRealm realm = entry.getClassRealm();
+ ClassRealm realm = (ClassRealm) entry.getClassRealm();
for (String exportedPackage : exportedPackages) {
extRealm.importFrom(realm, exportedPackage);
}