Redirecting Maven transfer messages to a file

One thing that is often bothering me about Maven is the extensive logging of download messages. Usually I am not interested in these messages unless something is really wrong, and then it is important to know, which URLs are accessed for download.

Before Maven 3.1 there were only poor chances to influence this behavior through the CLI. There were the options “-q” (quiet) and “-B” (batch mode), which influence the TransferListener implementation used by the Maven main class MavenCLI.

(from MavenCLI 3.0.4):

if ( quiet )
    transferListener = new QuietMavenTransferListener();
else if ( request.isInteractiveMode() )
    transferListener = new ConsoleMavenTransferListener( System.out );
    transferListener = new BatchModeMavenTransferListener( System.out );

With Maven 3.1 it was decided to use SLF4J as logging API. When using batch mode (-B), Maven will use Slf4jMavenTransferListener for logging, which is determined by method getBatchTransferListener().

(from MavenCLI 3.2.5):

if ( quiet )
    transferListener = new QuietMavenTransferListener();
else if ( request.isInteractiveMode() && !cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) )
    // If we're logging to a file then we don't want the console transfer listener as it will spew
    // download progress all over the place
    transferListener = getConsoleTransferListener();
    transferListener = getBatchTransferListener();

protected TransferListener getBatchTransferListener()
    return new Slf4jMavenTransferListener();

By default, the SLF4J SimpleLogger is used, which can be configured by the file


This allows already some decent influence on the message layout, threshold etc. Transfer messages can be suppressed by adding this property to the file:

All info level transfer messages will be suppressed, but this would also cover upload messages when deploying artifacts.

For a more advanced set up, the underyling logging framework can be replaced, e.g. with Log4J2. To do so, follow these simple steps:

1) delete lib/slf4j-simple-<version>.jar
2) add to lib/ folder:
3) add to conf/logging folder file log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Console name="Console" target="SYSTEM_OUT">
<!-- layout see -->
<PatternLayout pattern="[%level] %msg%n" />
<File name="TransferLog" fileName="mvn_transfer.log" immediateFlush="false" append="false">
<PatternLayout pattern="%msg%n"/>
<Root level="info">
<AppenderRef ref="Console" />
<Logger name="org.apache.maven.cli.transfer.Slf4jMavenTransferListener" level="info" additivity="false">
<AppenderRef ref="TransferLog" />

As a result, all transfer messages will be redirected to file “mvn_transfer.log”, while all other messages go to the console.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s