When you are using Maven in a cloud based CI system, e.g. with GitHub Actions, you are starting often with an empty repository and download Maven build dependencies on each run. This will happen fast as the dependencies are downloaded from a mirror, and with the batch option “-B” you’ll get just 2 lines per dependency. But still you get hundreds of lines of such messages:
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/3.0.0/maven-enforcer-plugin-3.0.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/3.0.0/maven-enforcer-plugin-3.0.0.pom (7.7 kB at 333 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer/3.0.0/enforcer-3.0.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer/3.0.0/enforcer-3.0.0.pom (8.7 kB at 334 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/34/maven-parent-34.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/34/maven-parent-34.pom (43 kB at 1.5 MB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/apache/23/apache-23.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/apache/23/apache-23.pom (18 kB at 635 kB/s)
This pollutes the build logs and usually does not provide benefit. So how to avoid this?
Download messages can be suppressed by reducing the log output of the Slf4jMavenTransferListener to warn level. This can be achieved by adding the system property
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
Now this needs to be added to each call of Maven commands. You might have multiple in your build pipelines and want to avoid to pollute the build scripts with them.
Usually it is a good idea to use the Maven Wrapper in your project. This does not only allow to pin the Maven version. Additionally you can just add common JVM options to a file. Your mvnw command that is checked in into your repository contains this line:
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
So you can just create the file .mvn/jvm.config and add the logging configuration property there. Now just use ./mvnw in your build pipeline scripts and you don’t get the download messages anymore.