WORKAROUND: Thanks to comment by Zart
Colwing, there is a workaround. Add
-Djansi.passthrough=true
to MAVEN_OPTS
. It is
not enough to add the flag to the command line; it needs to be seen by
JANSI before maven begins parsing the command line. See No color for
maven on Cygwin to track the issue.
Post
I'm quite happy Maven 3.5.0 has added color logging!
With earlier versions of maven, I used Jean-Christophe Guy's excellent maven-color extension. On Windows that involved some manual hacking of my maven installation, but on Mac, it was trivial with homebrew.
So now I'm getting color output from maven out of the box. Except when I don't.
You see, this new feature relies on the good JAnsi library. And JAnsi presently has an issue with color on Cygwin. When I'm at home, Cygwin is my mainstay, used on my gaming-cum-programming rig, so this is significant to me. What is the issue? No color—JAnsi detects I'm on Windows, and uses the native Windows console color handling, which doesn't work in Mintty or Xterm. Those use standard ANSI escape sequences, etc. rather than an OS-specific library.
Digging through the source for JAnsi, I find the trouble spot:
private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
Aha! The special Windows-handling code kicks in when the
os.name
system property contains "win" (in any case). Using
the jps
and jinfo
tools that come with the JDK,
I double-checked against a long-running maven build (16848 just was the
PID used by the JVM for this maven build; use jps
to list all
current PIDs):
$ jinfo -sysprops 16848 | grep os.name os.name = Windows 10
Some experimenting found a way to work around that:
MAVEN_OPTS=-Dos.name=Cygwin mvn clean
(You need to use MAVEN_OPTS
rather than passing -Dos.name=Cygwin
to maven; once maven starts the value is immutable.)
Color is back. It turns out, any value for os.name
will work
(for example, "Bob") as long as it doesn't contain "win". I picked
"Cygwin" for explicitness.
UPDATE: I have to rethink this. Sure I get color now, but
at the expense of maven test
failing as maven no longer
believes I'm on Windows, so is unhappy at the lack of a
/bin/sh
and general UNIX filesystem. One step forward, two
steps back.
No comments:
Post a Comment