You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/05/19 19:58:24 UTC
(maven) branch maven-4.0.x updated: Fix #11885: Disable ANSI colors when stdout is piped or redirected on JDK 22+ (#11887) (#12111)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new 9c8a1ef4fb Fix #11885: Disable ANSI colors when stdout is piped or redirected on JDK 22+ (#11887) (#12111)
9c8a1ef4fb is described below
commit 9c8a1ef4fb50046c02e344df8c33428df7cdaec1
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue May 19 21:58:18 2026 +0200
Fix #11885: Disable ANSI colors when stdout is piped or redirected on JDK 22+ (#11887) (#12111)
Change ForcedSysOut to SysOut so that JLine properly checks whether
stdout is a TTY before creating a system terminal. ForcedSysOut
bypasses this check, which causes JLine to create a non-dumb terminal
even when stdout is piped (since stdin is still a TTY), resulting in
ANSI escape codes appearing in piped output on JDK 22+ where the FFM
provider successfully creates a terminal from stdin alone.
With SysOut, JLine detects that stdout is not a TTY and falls back to
a dumb terminal, correctly disabling ANSI colors.
Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
.../main/java/org/apache/maven/cling/invoker/LookupInvoker.java | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
index 963d8b1706..5ec158321d 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
@@ -342,7 +342,7 @@ protected void doCreateTerminal(C context, TerminalBuilder builder) {
context.coloredOutput = context.coloredOutput != null ? context.coloredOutput : false;
context.closeables.add(out::flush);
} else {
- builder.systemOutput(TerminalBuilder.SystemOutput.ForcedSysOut);
+ builder.systemOutput(TerminalBuilder.SystemOutput.SysOut);
}
if (context.coloredOutput != null) {
builder.color(context.coloredOutput);
@@ -354,12 +354,10 @@ protected void doCreateTerminal(C context, TerminalBuilder builder) {
*/
protected final void doConfigureWithTerminal(C context, Terminal terminal) {
context.terminal = terminal;
- // tricky thing: align what JLine3 detected and Maven thinks:
+ // Align Maven's color setting with JLine's terminal detection:
// if embedded, we default to context.coloredOutput=false unless overridden (see above)
- // if not embedded, JLine3 may detect redirection and will create dumb terminal.
+ // if not embedded, JLine detects redirection via SysOut and will create dumb terminal.
// To align Maven with outcomes, we set here color enabled based on these premises.
- // Note: Maven3 suffers from similar thing: if you do `mvn3 foo > log.txt`, the output will
- // not be not colored (good), but Maven will print out "Message scheme: color".
MessageUtils.setColorEnabled(
context.coloredOutput != null ? context.coloredOutput : !Terminal.TYPE_DUMB.equals(terminal.getType()));