From b5c40510ea13aa47a3e8df92ba4f330d83ea6c9e Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 Jun 2026 07:19:56 +0000 Subject: [PATCH 1/2] [#11683] Install JUL-to-SLF4J bridge to route java.util.logging through Maven logging Adds the jul-to-slf4j bridge so that libraries using java.util.logging (JUL) have their log output routed through SLF4J and Maven's logging system, instead of writing directly to stderr. Co-Authored-By: Claude Opus 4.6 --- apache-maven/pom.xml | 7 +++++++ impl/maven-cli/pom.xml | 4 ++++ .../java/org/apache/maven/cling/invoker/LookupInvoker.java | 4 ++++ pom.xml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 426bd70a67b0..dac0617fc959 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -70,6 +70,13 @@ under the License. ${slf4jVersion} runtime + + + org.slf4j + jul-to-slf4j + ${slf4jVersion} + runtime + org.apache.maven.resolver maven-resolver-connector-basic diff --git a/impl/maven-cli/pom.xml b/impl/maven-cli/pom.xml index 72b4554c1c92..9e9de4421e52 100644 --- a/impl/maven-cli/pom.xml +++ b/impl/maven-cli/pom.xml @@ -195,6 +195,10 @@ under the License. org.slf4j slf4j-api + + org.slf4j + jul-to-slf4j + commons-cli commons-cli 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 5ec158321dbd..459f1046ef5c 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 @@ -90,6 +90,7 @@ import org.jline.terminal.impl.AbstractPosixTerminal; import org.jline.terminal.spi.TerminalExt; import org.slf4j.LoggerFactory; +import org.slf4j.bridge.SLF4JBridgeHandler; import org.slf4j.spi.LocationAwareLogger; import static java.util.Objects.requireNonNull; @@ -428,6 +429,9 @@ protected Consumer doDetermineWriter(C context) { } protected void activateLogging(C context) throws Exception { + // Route java.util.logging (JUL) through SLF4J + SLF4JBridgeHandler.removeHandlersForRootLogger(); + SLF4JBridgeHandler.install(); context.slf4jConfiguration.activate(); if (context.options().failOnSeverity().isPresent()) { String logLevelThreshold = context.options().failOnSeverity().get(); diff --git a/pom.xml b/pom.xml index fc17ca354224..f1549469538d 100644 --- a/pom.xml +++ b/pom.xml @@ -510,6 +510,11 @@ under the License. ${slf4jVersion} true + + org.slf4j + jul-to-slf4j + ${slf4jVersion} + ch.qos.logback logback-classic From 989f522181f294bcf9ecc6575388739eaeb63168 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Jun 2026 05:42:20 +0200 Subject: [PATCH 2/2] Guard JUL bridge installation with isInstalled() check Avoid redundantly removing handlers and reinstalling the SLF4JBridgeHandler on every activateLogging() call, which matters in embedded/resident-mode scenarios where Maven is invoked multiple times in the same JVM. Co-Authored-By: Claude Opus 4.6 --- .../java/org/apache/maven/cling/invoker/LookupInvoker.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 459f1046ef5c..56c7fb83d7b3 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 @@ -429,9 +429,10 @@ protected Consumer doDetermineWriter(C context) { } protected void activateLogging(C context) throws Exception { - // Route java.util.logging (JUL) through SLF4J - SLF4JBridgeHandler.removeHandlersForRootLogger(); - SLF4JBridgeHandler.install(); + if (!SLF4JBridgeHandler.isInstalled()) { + SLF4JBridgeHandler.removeHandlersForRootLogger(); + SLF4JBridgeHandler.install(); + } context.slf4jConfiguration.activate(); if (context.options().failOnSeverity().isPresent()) { String logLevelThreshold = context.options().failOnSeverity().get();