Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven MINGW support requires --add-opens java.base/java.lang=ALL-UNNAMED

Tags:

java

maven

After I upgraded my Maven from 3.9.6 into 3.9.8 every command that I run in Git Bash of Git for Windows 2.45.2.windows.1 (Mintty 3.7.1) prints this message twice. For example:

$ mvn --version
MINGW support requires --add-opens java.base/java.lang=ALL-UNNAMED
MINGW support requires --add-opens java.base/java.lang=ALL-UNNAMED
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: C:\develop\apache-maven-3.9.8
Java version: 17.0.11, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-17
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

I've tried to find the code in Apache Maven that prints this message but didn't find anything like that. Looked at the repository cloned from https://github.com/apache/maven Googling and reading the release notes also didn't help. The only thing that I know is this behavior has started from Maven 3.9.7.

Could someone shed light on this change and explain why and where it was done in the Maven source code? Or maybe it's printed by one of its dependencies? By which one?

like image 693
Rostislav Krasny Avatar asked Nov 23 '25 13:11

Rostislav Krasny


1 Answers

Found by myself. This message is printed by the MingwSupport#getConsoleName() method of the jansi library version 2.4.1:

    public String getConsoleName(boolean stdout) {
        try {
            Process p = new ProcessBuilder(ttyCommand)
                    .redirectInput(getRedirect(stdout ? FileDescriptor.out : FileDescriptor.err))
                    .start();
            String result = waitAndCapture(p);
            if (p.exitValue() == 0) {
                return result.trim();
            }
        } catch (Throwable t) {
            if ("java.lang.reflect.InaccessibleObjectException"
                    .equals(t.getClass().getName())) {
                System.err.println("MINGW support requires --add-opens java.base/java.lang=ALL-UNNAMED");
            }
            // ignore
        }
        return null;
    }

and the code that needs --add-opens java.base/java.lang=ALL-UNNAMED is:

    /**
     * This requires --add-opens java.base/java.lang=ALL-UNNAMED
     */
    private ProcessBuilder.Redirect getRedirect(FileDescriptor fd) throws ReflectiveOperationException {
        // This is not really allowed, but this is the only way to redirect the output or error stream
        // to the input.  This is definitely not something you'd usually want to do, but in the case of
        // the `tty` utility, it provides a way to get
        Class<?> rpi = Class.forName("java.lang.ProcessBuilder$RedirectPipeImpl");
        Constructor<?> cns = rpi.getDeclaredConstructor();
        cns.setAccessible(true);
        ProcessBuilder.Redirect input = (ProcessBuilder.Redirect) cns.newInstance();
        Field f = rpi.getDeclaredField("fd");
        f.setAccessible(true);
        f.set(input, fd);
        return input;
    }

Maven 3.9.6 uses an older jansi 2.4.0 and Maven 3.9.7/3.9.8 use a newer jansi 2.4.1

UPDATE: I've reported this as a bug to the Jansi project and also made a pull request with a fix.

like image 173
Rostislav Krasny Avatar answered Nov 25 '25 06:11

Rostislav Krasny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!