78

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?

rapt
  • 11,810
  • 35
  • 103
  • 145

3 Answers3

166

Try mvn -help

 -l,--log-file <arg>  Log file to where all build output will go.                               

mvn <your parameters> --log-file log.txt

Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
  • Thank you, and to the others how answered. All your answers worked for me. – rapt Mar 16 '12 at 05:13
  • 3
    There is a way to append the content of mvn command in log.txt file? I mean, each time you run a mvn command and save it in log.txt file, the previous content is deleted. – Carlos Vázquez Losada Oct 01 '17 at 08:13
  • 6
    Output is no longer printed to console when `--log-file` is used. – Evgeni Sergeev Aug 14 '18 at 18:32
  • 5
    It's possible to print to both ? file and console – Adir Dayan Jan 23 '20 at 18:18
  • This was my problem! Increasing `Xmx` both in `MAVEN_OPTS` or `argLine` for `maven-surefire-plugin` didn't help. `mvn -l mvn-log-666.txt` worked like a charm! Log file size is about 2.7 MB. – Dmitriy Popov May 08 '20 at 15:46
  • For those like me wanting to log both to a file and to the console, appending to the file without recreating it all the time, it's pretty easy as long as you are on a UNIX/Linux environment: use tee instead of --log-file: mvn clean install | tee log.txt -a – Thales Valias Jan 22 '21 at 17:33
  • 1
    When I want both stdout/stderr *and* a file (with a timestamped name) I do this: mvn ... 2>&1 | tee mvn.log-`date +%Y%m%d-%H%M%S` – Max Spring Feb 25 '21 at 00:51
  • @MaxSpring for linux/macOs you right. The question was for windows 7 .... – Andrzej Jozwik Feb 25 '21 at 09:55
  • I just used the old DOS Shell redirect > in Windows Terminal like so: mvn spring-boot:run > output.log – Net Dawg Jan 06 '22 at 20:34
  • This does not work if the maven aborts unexpected. For example compiling issues on JDK versions. – Pwnstar Mar 30 '22 at 08:20
7

Just give it a try:

mvn dependency:tree -Dverbose -DoutputFile=resout.out

within the same folder where the pom file is located.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
0

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
mattdibi
  • 641
  • 10
  • 23
Paul
  • 7,155
  • 8
  • 41
  • 40