Lucas Lucas - 1 month ago 8
Java Question

Execute maven goal without a project

I have some automation that uses

mvn
to download artifacts to a local filesystem so they can be used outside of maven. Basically, I do something like this:

#!/bin/bash
mvn dependency:get \
-DgroupId="my.group.id" \
-DartifactId="$1" \
-Dversion="$2" \
-Dpackaging="war" \
-DremoteRepositories="http://my.repo/nexus/content/repositories/foo"


The problem (and its not really a problem) is that I get the following output:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building some-other-project 1.2.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------


If I happen to run this from a sub folder of
some-other-project
. This is confusing to the person running this script as the
dependency:get
execution does not actually build the project. Short of capturing and processing the output to strip that info, is there a simple way to tell
mvn
that it is just running a goal without an associated project?

Answer

You can suppress all INFO output by passing --quiet flag (or -q).

If you'd like to have some INFO's while dropping the rest, you can identify all the components you'd like to silence by doing searches against Maven github and configure the logging properties to exclude those.

E.g. you can add the following flag: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.event.ExecutionEventLogger=ERROR for that Scanning for projects... message.