Stop logging downloads from repository on Maven - 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.

Related

Modify maven test output in console

Firing mvn clean test
prints this:
Due to some conditions I skip tests dynamically.
However, I'd like to print the cause for skipping to the console, like it's done for failing tests:
is there any way to archieve this?
Alternativly, how could I properly log it, so it's still recognizable between all the other logs?
I'm using log4j for logging. Any Ideas?

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.

Send maven output to file

On Windows 7, I am trying to send the output of a maven-3 command to a text file.
I call the command from the root of the project I am trying to analyze.
The command is:
mvn dependency:tree -Dverbose -Dincludes=commons-collections -DoutputFile=C:\Users\myname\Documents\output.txt
When I run the command without the outputFile parameter, I see the output sent to the console.
But when I use it with the outputFile parameter, the output file is empty.
Any idea what I am missing here?
Try mvn -help
-l,--log-file <arg> Log file to where all build output will go.
mvn <your parameters> --log-file log.txt
Just give it a try:
mvn dependency:tree -Dverbose -DoutputFile=resout.out
within the same folder where the pom file is located.
Old school, but it's what I knew. One caveat is that the mvn command does not return when done to the cli, but for some purposes this is acceptable.
mvn "-Dexec.args=-classpath %classpath com.mycompany.test" -Dexec.executable=/Downloads/jdk1.7/bin/java exec-maven-plugin:1.2.1:exec > /tmp/Out

How to get Maven dependencies printed to a file in a readable format?

I am working on a big projects with many pom.xml files and I need to specify all the libraries that I use. This means that I need to read pom.xml files recursively and get groupId, artifactId, scope and version. I checked out mvn dependency:tree but I can't find a way to print it to a file in a readable format. I saw appendOutput but I saw no example on how to use it in cmd. I saw some solutions done in Linux but I only have access to Windows XP.
This can (at least now) be done with command line options to the dependency:tree plugin.
Try:
mvn dependency:tree -Doutput=/path/to/file
Reference: Maven Dependency Plugin Page
You only asked about "readable" format, but you can also pass the -DoutputType parameter with various options. Also note that the version I have installed, I get the following warning:
[WARNING] The parameter output is deprecated. Use outputFile instead.
So, consider trying it with -DoutputFile=/path/to/file
Also, I was unable to get the -DoutputType paramater to give me anything other than the default text, but didn't have a chance to play around with it. YMMV.
If you have multiple modules under the same repo/project and want the dependencies of all the modules in one file, so as to be able to diff b/w one build and another to see if something changed somewhere, you can do
$project_dir> mvn dependency:tree -DoutputFile=<absolute_path_to_file> -DappendOutput=true
e.g.
$project_dir> mvn dependency:tree -DoutputFile=`pwd`/mvn_dependency_tree.txt -DappendOutput=true
See other options available at https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html
Adding the
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
</plugin>
plugin produces a classes/META-INF/maven/dependencies.properties file with the project dependencies easily parseable.
Example of the output produced:
# Project dependencies generated by the Apache ServiceMix Maven Plugin
# Generated at: Mon Oct 10 17:43:00 CEST 2011
groupId = my.group.name
artifactId = my.artifact.name
version = 0.0.1-SNAPSHOT
my.group.name/my.artifact.name/version = 0.0.1-SNAPSHOT
# dependencies
junit/junit/version = 4.8
junit/junit/type = jar
junit/junit/scope = test
org.easymock/easymock/version = 2.4
org.easymock/easymock/type = jar
org.easymock/easymock/scope = test
On GNU/Linux I would just do mvn dependency:tree > myFile. However, if you're restricted to Windows only, than I would look for Windows' syntax for streaming the output of a command.
According to this site (just a top-results from Google) it seems that Windows' console also use > sign to direct the output stream to i.e. a file.
So would you mind trying this?
I have run the below command and got the file having all the maven dependency.
mvn dependency:tree -DoutputFile=temp/mvn_dependency_tree.txt
This command will create a folder named "temp" and inside this folder a file name mvn_dependency_tree.txt will be created with all the dependencies.
You can always install MinGW and MSYS and then use the Linux examples using dependency:tree in Windows
Perhaps effective-pom (in conjunction with some linux commands for saving the file) can be sufficient for your needs.

Can Maven be made less verbose?

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.

Resources