How to time the different stages of maven execution

Out of the box solution is the takari maven profiler: https://github.com/takari/maven-profiler

Sample output from its page:

org.apache.maven:maven-core:3.1.2-SNAPSHOT

    clean 176ms
        org.apache.maven.plugins:maven-clean-plugin:2.5 (default-clean) 176ms

    initialize 408ms
        org.codehaus.mojo:buildnumber-maven-plugin:1.2 (create-noncanonicalrev) 349ms
        org.codehaus.mojo:buildnumber-maven-plugin:1.2 (create-buildnumber) 59ms

    generate-sources 408ms
        org.codehaus.modello:modello-maven-plugin:1.8.1 (standard) 369ms
        org.codehaus.modello:modello-maven-plugin:1.8.1 (standard) 28ms
        org.codehaus.modello:modello-maven-plugin:1.8.1 (standard) 11ms

    generate-resources 933ms
        org.apache.maven.plugins:maven-remote-resources-plugin:1.4 (default) 932ms

    process-resources 225ms
        org.apache.maven.plugins:maven-resources-plugin:2.6 (default-resources) 224ms

    compile 4s 522ms
        org.apache.maven.plugins:maven-compiler-plugin:2.5.1 (default-compile) 4s 522ms

    process-classes 6s 880ms
        org.codehaus.mojo:animal-sniffer-maven-plugin:1.6 (check-java-1.5-compat) 5s 814ms
        org.codehaus.plexus:plexus-component-metadata:1.5.5 (default) 946ms
        org.sonatype.plugins:sisu-maven-plugin:1.1 (default) 120ms

    process-test-resources 173ms
        org.apache.maven.plugins:maven-resources-plugin:2.6 (default-testResources) 173ms

    test-compile 818ms
        org.apache.maven.plugins:maven-compiler-plugin:2.5.1 (default-testCompile) 818ms

    process-test-classes 134ms
        org.codehaus.plexus:plexus-component-metadata:1.5.5 (default) 110ms
        org.sonatype.plugins:sisu-maven-plugin:1.1 (default) 23ms

    test 11s 306ms
        org.apache.maven.plugins:maven-surefire-plugin:2.12 (default-test) 11s 306ms

    package 1s 371ms
        org.apache.maven.plugins:maven-jar-plugin:2.4 (default-jar) 502ms
        org.apache.maven.plugins:maven-site-plugin:3.3 (attach-descriptor) 869ms

https://github.com/jcgay/maven-profiler is a similar handy tool. It's easy to setup and use. (Having something like it or EventSpy takari/maven-profiler in core Maven as an option would certainly be neat; comment in https://issues.apache.org/jira/browse/MNG-4639 ..)


This is the quickest possible way:

export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS \
                   -Dorg.slf4j.simpleLogger.showDateTime=true" 
mvn test

Results in

MAVEN_OPTS="-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS -Dorg.slf4j.simpleLogger.showDateTime=true" mvn test
17:06:07,330 [INFO] Scanning for projects...
17:06:07,447 [INFO] 
17:06:07,447 [INFO] ------------------------------------------------------------------------
17:06:07,448 [INFO] Building bimble-server 0.0.1-SNAPSHOT
17:06:07,448 [INFO] ------------------------------------------------------------------------
17:06:07,747 [INFO] 
17:06:07,748 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ bimble-server ---

If you then add that environment variable to your shell's config file (like ~/.bashrc or ~/.profile) you will have those timings every time you use Maven.

Based on info from Stanley Hillner's blog: