[regression] Maven4 unable to pass settings path on Windows
Affected version
4.0.0-rc-5
Bug description
Updating to Maven4 breaks my usage scenario:
$ echo $MAVEN_ARGS
-s D:\projects\mmm\conf\mvn\settings.xml -Dsettings.security=D:\projects\mmm\conf\mvn\settings-security.xml
$ mvn -v
[ERROR] Error executing Maven.
[ERROR] The specified user settings file does not exist: D:\projects\mmm\projectsmmmconfmvnsettings.xml
To me it looks as if maven4 does some transformation with backslashes in path's.
Maybe also the wrapper script calling maven via Java is causing this effect.
I diffed the mvn wrapper script and found that in 3.9.9 it was containing this relevant block that was removed in maven 4.0:
# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
# TODO classpath?
fi
UPDATE: I do not believe this is related to the bug. I rather expect the bug to be in the Java code.
When I downgrade to maven 3.x it works again:
$ mvn -v
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.fusesource.jansi.internal.JansiLoader in an unnamed module (file:/D:/projects/mmm/software/mvn/lib/jansi-2.4.1.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: D:\projects\mmm\software\mvn
Java version: 25, vendor: Eclipse Adoptium, runtime: D:\projects\mmm\software\java
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"
Please note that when setting e.g. MAVEN_ARGS on Windows, I expect this to work in different environments:
- MS DOS (aka CMD)
- Git-Bash
- Maybe even in cygwin (see #10810 that seems related)
I therefore have to specify the PATH syntax in Windows style with drive letter followed by colon (and using backslashes).
If I test the same in CMD terminal on Windows it is working:
D:\projects\mmm>echo %MAVEN_ARGS%
-s D:\projects\mmm\conf\mvn\settings.xml -Dsettings.security=D:\\projects\\mmm\\conf\\mvn\\settings-security.xml
D:\projects\mmm>mvn -v
Apache Maven 4.0.0-rc-5 (fb3ecaef88106acb40467a450248dfdbd75f3b35)
Maven home: D:\projects\mmm\software\mvn
Java version: 25, vendor: Eclipse Adoptium, runtime: D:\projects\mmm\software\java
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 11", version: "10.0", arch: "amd64", family: "winnt"
Note that mvnd does translate (only the current directory) when running in Cygwin, see https://github.com/apache/maven-mvnd/blob/7b309de9ab8e8ed4e65cb43f59c9a3e22edc69e0/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java#L97-L109
Note that
mvnddoes translate (only the current directory) when running in Cygwin, see https://github.com/apache/maven-mvnd/blob/7b309de9ab8e8ed4e65cb43f59c9a3e22edc69e0/daemon/src/main/java/org/mvndaemon/mvnd/cli/EnvHelper.java#L97-L109
Nice feature. However, I stopped using cygwin and only use git-bash that is based on MINGW.
- Windows C:\Users
- git-bas: /c/users
- cygwin: /cygdrive/c/users
I also implemented such support in my product IDEasy: https://github.com/devonfw/IDEasy/blob/main/cli/src/test/java/com/devonfw/tools/ide/os/WindowsPathSyntaxTest.java
It already supports mvn and mvnw among gradle, gradlew, and tons of other tools.
I am planning support for mvnd soon.
BTW: Besides this product flavour sneaking in with /cygdrive I especially dislike that cygwin creates its own users home directory so you have two different home directories as a Windows user what IMHO causes a lot of trouble and confusion.
However cygwin is still great if you want to install packages and special GNU Linux software without virtualisation (WSL2 or even a full VM).
@khmarbaise I would even create a PR to fix such issue myself. Do you happen to have some instructions how to setup and debug Maven directly from its source-code? I always failed at this point to deep dive into maven core. Implementing and debugging Mojos is what I have done already a lot... So if you have a guess how to start, I am happy to support by creating a PR.
This bug seems to be slightly related to #10834
Some first traces browsing the source-code:
- https://github.com/apache/maven/blob/f93b5629a09efd80c04d9e99ca1f4f5d3f70cdf7/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java#L219-L221
- https://github.com/apache/maven/blob/f93b5629a09efd80c04d9e99ca1f4f5d3f70cdf7/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java#L247-L253
- https://github.com/apache/maven/blob/f93b5629a09efd80c04d9e99ca1f4f5d3f70cdf7/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/Options.java#L127
- https://github.com/apache/maven/blob/f93b5629a09efd80c04d9e99ca1f4f5d3f70cdf7/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java#L142-L147