Add timestamps to Maven output
Maven output is by default something like that:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
....
This is not bad and readable but for a CI it doesn't give any execution duration information. There are plugins like tesla-profiler and so on to have statistics about the execution durations but they all have issues if your setup is not too close to the default one and in particular you can have some missed mojo executions.
However, Maven uses a logger...so it should be doable to add the timestamp to the log lines without much effort and it should give you some minimal insights to start checking what is taking a long time to be executed :).
What is important to understand for that is Maven is using SLF4J for its logging. Its default binding is an extended simple logger flavor of SLF4J. Therefore you can use simple logger configuration. You can do it in the simplelogger.properties file you can find in your maven conf/logging directory but since it is common to activate it only on the CI or temporarly on your local machine to keep the log readable we will use the system properties.
To do that we need two properties:
- org.slf4j.simplelogger.showDateTime: a boolean to add the timestamp in the output
- org.slf4j.Simplelogger.dateTimeFormat: a SimpleDateFormat which formats the timestamp activated by previous property
This means that to get the time in the output you can add these system properties on the JVM:
-Dorg.slf4j.simpleLogger.showDateTime=true
-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
Once done (for instance adding them in your MAVEN_OPTS) you will get this kind of output:
$ MAVEN_OPTS="-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss" mvn install
11:34:05 [INFO] Scanning for projects...
11:34:06 [INFO] ------------------------------------------------------------------------
11:34:06 [INFO] Reactor Build Order:
11:34:06 [INFO]
And here we are, you can check how long take each mojo and speed up your build if needed :).
Side note: there are other configuration for simple logger default output of Maven, like showThreadName=true which allows to add the thread name in the output and can allow to track executions in concurrent builds if the thread name are set (Thread.currentThread().setName(...) in a JUnit rule is enough for instance).
From the same author:
In the same category: