Can Maven be made less verbose? - maven

Maven spews out far too many lines of output to my taste (I like the Unix way: no news is good news).
I want to get rid of all [INFO] lines, but I couldn't find any mention of an argument or config settings that controls the verbosity of Maven.
Is there no LOG4J-like way to set the log level?

You can try the -q switch.
-q,--quiet Quiet output - only show errors

-q as said above is what you need. An alternative could be:
-B,--batch-mode
Run in non-interactive (batch) mode
Batch mode is essential if you need to run Maven in a non-interactive, continuous integration environment. When running in non-interactive mode, Maven will never stop to accept input from the user. Instead, it will use sensible default values when it requires input.
And will also reduce the output messages more or less to the essentials.

My problem is that -q is too quiet. I'm running maven under CI
With Maven 3.6.1 (April 2019), you now have an option to suppress the transfer progress when downloading/uploading in interactive mode.
mvn --no-transfer-progress ....
or in short:
mvn -ntp ... ....
That is what Ray proposed in the comments with MNG-6605 and PR 239.

Official link :
https://maven.apache.org/maven-logging.html
You can add in the JVM parameters :
-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN
Beware of UPPERCASE.

Use the -q or --quiet command-line options

If you only want to get rid of the [INFO] messages you also could do:
mvn ... | fgrep -v "[INFO]"
To suppress all outputs (except errors) you could redirect stdout to /dev/null with:
mvn ... 1>/dev/null
(This only works if you use bash (or similar shells) to run the Maven commands.)

The existing answer help you filter based on the log-level using --quiet. I found that many INFO messages are useful for debugging, however the downloading artifact log messages such as the following were noisy and not helpful.
Downloading: http://nexus:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
I found this solution:
https://blogs.itemis.com/en/in-a-nutshell-removing-artifact-messages-from-maven-log-output
mvn clean install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

Maven 3.1.x uses SLF4j for logging, you can find instructions how to configure it at https://maven.apache.org/maven-logging.html
In short: Either modify ${MAVEN_HOME}/conf/logging/simplelogger.properties, or set the same properties via the MAVEN_OPTS environment variable.
For example: setting MAVEN_OPTS to -Dorg.slf4j.simpleLogger.log.org.apache.maven.cl‌​i.transfer.Slf4jMave‌​nTransferListener=wa‌​rn configures the logging of the batch mode transfer listener, and -Dorg.slf4j.simpleLogger.defaultLogLevel=warn sets the default log level.

Related

Make maven output show progressed sub-modules only

I am working with an automatic build script in maven 3.x. The parent project contains of more than 60 modules. The compilation is done in a shell script simplified this way:
for each module:
cd module
mvn clean install > compile.$module.log
echo "Compiled $module"
I like to see a list of compiled modules in order to see the progress or the build. I like to have a big maven command and avoid the manual for loop. I hope to speed up the build this way, since splitting the parent project into more independent modules is not a short time option, yet.
The --quiet flag might be enough already. Alternatively a user defined logging implementation would be fine as well, as described in the manual (https://maven.apache.org/maven-logging.html)
The questions are:
What is the prefered way to modify maven log output?
Does anyone already know a ready-to-use plugin for my purpose?
Thanks

What is the meaning of clean test -P?

For one of the project, we are supporting I see the Maven
clean test -P DEV,CI
inside the Goals and Options for the build option of Jenkins. Its is causing the Sonar analysis of the test jobs behave incorrectly.
I tried to find the meaning of -P option, but did not get any solutions so far.
The Maven CLI Options Reference documents what -P means:
-P,--activate-profiles <arg> Comma-delimited list of profiles to activate
It is related to profiles. Read more at Introduction to Build Profiles.

Stop logging downloads from repository on Maven

Is there a way to remove redundant output lines that informs about every small download Maven made from the repository. I only want to see output of the actual plugins.
Is there a plugin that is in charge of all this output that I can configure?
Thanks!
I dont think you can achieve by changing maven settings.
Only options i knw are mvn -q hides the [INFO] lines and mvn -X shows the debug messages.
You should look to save the log messages in a file ans then use unix grep command to filter messages which you want.
To suppress downloading/downloaded messages in maven I use the following command:
mvn --batch-mode ... bla bla bla ... | grep -v 'Download.* http'
It is will suppress downloading/downloaded messages without suppressing anything else, i.e. the uploading/uploaded [INFO] messages, which anyone in their right mind would want to keep.

Which Maven goal to use as no-op (for scripting purposes)?

I have a script on Jenkins CI which optionally does dependency:go-offline. The other option should be to do nothing. But I can't put "" in there - it must be a goal.
So - which one would you pick? It should:
Be in central, always reachable
Take minimum time
Have minimal output
Have no side effects
I was thinking of some help:... goal but those tend to have a lot of output. Any better?
You can use this goal and option:
mvn --quiet help:help
the -q,--quiet option causes the output to only show errors.
Note that Jenkins allows you to add options like --quiet as diplayed in the usage: mvn [options] [<goal(s)>]. You configure these in the Jenkins job’s “Goals and options” field.
Check mvn --help output for further information.
I know this is an old question, but I came across it when I had the same requirement and it's still unanswered, so I'm posting for anyone who needs it in future.
This still depends on the current project, but could be useful if you don't want to hardcode a specific plugin for some reason:
mvn -pl ./ validate
-pl ./ means only current project, ignore submodules. Alternatively you could specify specific project by relative path or [groupId]:artifactId.
validate is the first phase of the Default Lifecycle. Doesn't change or build anything.
Alternatively, if you don't have a maven project at all, some maven plugins, or rather specific plugin goals, can be executed without it. E.g.:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:help
It would still scan projects if it sees a POM in the current directory. And of course you still need to have the plugin in your local repository.

Jenkins multi-configuration project user-defined axis environment variable

I am trying to set up a multi-configuration project in Jenkins with a single user-defined axis (call it "axis"). The value associated with each configuration would then be used to invoke top-level maven targets in ${axis}/pom.xml. The trouble is, I can't find the proper syntax for this, if indeed it does exist (${axis}, $axis, $AXIS, and ${env.axis} all fail). I would think it would be shell syntax, which it doesn't seem to be, but regardless it should be either simple or impossible. Is it possible?
Is your Jenkins installation running on Windows?
For each Custom Axis, an environment variable is created. You can refer to your custom axis using ${axis} if your server is running Linux, but on Windows you must refer to it as %axis%
${axis}/pom.xml should work in my experience.
I appreciate that OP has solved this in a different way, but for the record the following works in Hudson in Windows and Linux. I haven't tried it in Jenkins:
The syntax you need for this is simply $axis/pom.xml
I defined an axis of BuildProfile=compile unitTest integrationTest
And in the Maven 3 configuration (under Advanced properties) a POM file of $BuildProfile/pom.xml
The resulting builds gave the following output in the console (edited for brevity):
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=compile -f compile/pom.xml
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=unitTest -f unitTest/pom.xml
[1.7.0_25] $ C:\Users...\bin\mvn.bat clean install -V -B
-DBuildProfile=integrationTests -f integrationTests/pom.xml
We use a jdk axis and just use the name of the jdk so I think you could just use axis/pom.xml

Resources