Giter VIP home page Giter VIP logo

maven-buildtime-extension's Introduction

Build Status

Overview

Maven doesn't give you detailed information about where your build is taking the most time. This build time extension displays the duration for each goal that is run during your build.

Usage

Put this in your pom.xml to find out why you are slow. By default this will log only to maven debug -X,--debug, however debug is quite noisy, so you can enable output to normal log via the property buildtime.output.log in your pom or via commandline -Dbuildtime.output.log=true.

Capture the results to a CSV file

Thanks to @leonard84 for the contribution. You'll need to set a property to enable this feature. Eventually, we can enhance this functionality to include other output formats. I personally would like to publish the results to an InfluxDb instance.

mvn compile -Dbuildtime.output.csv=true -Dbuildtime.output.csv.file=classes\out.csv

Maven introduced slf4j in version 3.2 which broke this build extension for Maven 3.0 users. Version 2.0+ will work with the latest version of Maven.

Maven 3.3 - Use version 3.0+

With version 3.0.0 we switched to Maven's EventSpy API which increases the compatibility with other tools, e.g. Jenkins which also use this API to instrument Maven. However this requires a different way of loading the extension. This also requires at least Maven 3.3+.

Create the following file <projectroot>/.mvn/extensions.xml with this as content

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
    <extension>
        <groupId>co.leantechniques</groupId>
        <artifactId>maven-buildtime-extension</artifactId>
        <version>3.0.0</version>
    </extension>
</extensions>

Due to MNG-5786 you might need to use Maven 3.3.9 if <projectroot>/.mvn/extensions.xml is not picked up. You can also check the build log for the presence of the string BuildTimeEventSpy is registered. which is logged if the extension was successfully activated.

Maven 3.2 - Use version 2.0+ Deprecated

<build>
    <extensions>
        <extension>
            <groupId>co.leantechniques</groupId>
            <artifactId>maven-buildtime-extension</artifactId>
            <version>2.0.3</version>
        </extension>
    </extensions>
</build>

Maven 3.0 - Use version 1.0 Deprecated

Version 1 works with Maven 3.0. All future improvements and bug fixes will occur on the 2.0 version of this build extension

<build>
    <extensions>
        <extension>
            <groupId>co.leantechniques</groupId>
            <artifactId>maven-buildtime-extension</artifactId>
            <version>1.0.1</version>
        </extension>
    </extensions>
</build>

One-off execution

Instead of modifying the POM you can also perform a one-off execution. In this case you must manually download the extension (only once, before the first execution) and then explicitly provide it as a command line argument:

VERSION=2.0.3
mvn -q dependency:get -Dartifact="co.leantechniques:maven-buildtime-extension:$VERSION"
mvn compile -Dmaven.ext.class.path="$HOME/.m2/repository/co/leantechniques/maven-buildtime-extension/$VERSION/maven-buildtime-extension-$VERSION.jar"

Example

[INFO] Reactor Summary:
[INFO]
[INFO] CoEfficient ....................................... SUCCESS [0.103s]
[INFO] coefficient-core .................................. SUCCESS [0.903s]
[INFO] coefficient-scm ................................... SUCCESS [0.314s]
[INFO] coefficient-heatmap ............................... SUCCESS [0.202s]
[INFO] coefficient-test-ratios ........................... SUCCESS [0.114s]
[INFO] coefficient-mvn ................................... SUCCESS [0.769s]
[INFO] coefficient-acceptance-test ....................... SUCCESS [0.305s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.490s
[INFO] Finished at: Sun Jul 14 16:10:34 CDT 2013
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
[INFO] Build Time Summary:
[INFO]
[INFO] coefficient
[INFO]   maven-clean-plugin:clean ................................. [0.079s]
[INFO] coefficient-core
[INFO]   maven-clean-plugin:clean ................................. [0.007s]
[INFO]   maven-resources-plugin:resources ......................... [0.261s]
[INFO]   maven-compiler-plugin:compile ............................ [0.569s]
[INFO] coefficient-scm
[INFO]   maven-clean-plugin:clean ................................. [0.007s]
[INFO]   maven-resources-plugin:resources ......................... [0.002s]
[INFO]   maven-compiler-plugin:compile ............................ [0.281s]
[INFO] coefficient-heatmap
[INFO]   maven-clean-plugin:clean ................................. [0.003s]
[INFO]   maven-resources-plugin:resources ......................... [0.002s]
[INFO]   maven-compiler-plugin:compile ............................ [0.172s]
[INFO] coefficient-test-ratios
[INFO]   maven-clean-plugin:clean ................................. [0.005s]
[INFO]   maven-resources-plugin:resources ......................... [0.002s]
[INFO]   maven-compiler-plugin:compile ............................ [0.085s]
[INFO] coefficient-mvn
[INFO]   maven-clean-plugin:clean ................................. [0.005s]
[INFO]   maven-plugin-plugin:descriptor ........................... [0.628s]
[INFO]   maven-resources-plugin:resources ......................... [0.002s]
[INFO]   maven-compiler-plugin:compile ............................ [0.099s]
[INFO] coefficient-acceptance-test
[INFO]   maven-clean-plugin:clean ................................. [0.002s]
[INFO]   maven-resources-plugin:resources ......................... [0.002s]
[INFO]   maven-compiler-plugin:compile ............................ [0.002s]
[INFO] ------------------------------------------------------------------------

Release Process

Sonatype requires all published components to be signed. These commands prompt for a gpg passphase. (Reminder for me: It is in your password vault)

./mvnw release:prepare

./mvnw release:perform

2018-05-30 Had to add this command to the my console to get it signed:

GPG_TTY=$(tty)
export GPG_TTY

maven-buildtime-extension's People

Contributors

benkiefer avatar darrinholst avatar inikolaev avatar jason-hooker avatar leonard84 avatar ryber avatar seanf avatar stephan202 avatar timgifford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maven-buildtime-extension's Issues

CSV Fails to write if pom.xml does not make target

Steps to reproduce

  1. add .mvn/extensions.xml
  2. run build with -Dbuildtime.output.csv=true -Dbuildtime.output.csv.file=output.csv
  3. pom.xml does not run anything that creates target/ directory (for instance it's a parent pom)

Workaround 1:

Instead of -Dbuildtime.output.csv.file=output.csv provide the absolute path like -Dbuildtime.output.csv.file=/Users/joseph/my_project/output.csv

Workaround 2:

Create target directory, but ensure that your mvn command does not run clean phase.

Stacktrace

[ERROR] Could not write report
java.io.FileNotFoundException: target/output.csv (No such file or directory)
    at java.io.FileOutputStream.open0 (Native Method)
    at java.io.FileOutputStream.open (FileOutputStream.java:270)
    at java.io.FileOutputStream.<init> (FileOutputStream.java:213)
    at java.io.FileOutputStream.<init> (FileOutputStream.java:162)
    at java.io.PrintWriter.<init> (PrintWriter.java:263)
    at co.leantechniques.maven.buildtime.output.CsvReporter.performReport (CsvReporter.java:39)
    at org.apache.maven.cli.BuildTimeEventSpy.doReport (BuildTimeEventSpy.java:81)
    at org.apache.maven.cli.BuildTimeEventSpy.onEvent (BuildTimeEventSpy.java:65)
    at org.apache.maven.cli.BuildTimeEventSpy.onEvent (BuildTimeEventSpy.java:46)
    at org.apache.maven.eventspy.internal.EventSpyDispatcher.onEvent (EventSpyDispatcher.java:104)
    at org.apache.maven.eventspy.internal.EventSpyExecutionListener.sessionEnded (EventSpyExecutionListener.java:61)
    at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire (DefaultExecutionEventCatapult.java:64)
    at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire (DefaultExecutionEventCatapult.java:42)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:137)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Use version for tag and commit message

Current:

Uses the default from the release plugin.

[maven-release-plugin] copy for tag maven-buildtime-extension-2.0 

Preferred:

Tag: 2.0
Message: [maven-release-plugin] Release 2.0

plugin timestamp are not showing

I don't see the plugin timings like in the README.md example.
I'm doing a reactor build, and I see the time it took each project. No plugin-level timings.

maven.config

-Dbuildtime.output.log=true

extensions.xml

<extensions>
  <extension>
    <groupId>co.leantechniques</groupId>
    <artifactId>maven-buildtime-extension</artifactId>
    <version>3.0.3</version>
  </extension>
</extensions>

[FR] per-plugin cumulative statistic

Would it be possible to add yet another summary - cumulative, per plugin statistic? Currently, your extension output more detailed times for each module. It would be great to have "totals" section, where times for each plugin for each module would be summed / accumulated (to have overview which plugin impacts the build the most in total)

Output to File (csv)

It would be great if you could add an option to redirect the output to a file.
Maybe even in a simple csv format "Module";"Mojo";"Time" or something like that,
so that it can be analyzed easier.

Generate report even though JVM is shutting down

When the Maven build is part of a Jenkins job and a timeout occurs, no report is written.
Having the report could help to understand why the built lasted for so long.

It would be great if the extension could try to write the information already available, even though the JVM is forcibly shutting down.
This probably means relying on java.lang.Runtime.addShutdownHook(Thread), i.e. this is on a best effort basis.

In case the build is successful, then there is no need to write the same report twice.

Incorrect timing when exception occurred

When a java process is locking a file in the background and I run the build again, the build fails and the extension reports a large negative number (possibly minimum integer value).

[INFO] maven-clean-plugin:clean ................................. [-1389029550.705s]

Add option to log only if build succeeds

#8 mentions the "spam" problem with all the timing output at the end of a build.

It would be useful to have an option to log the build times only when the build succeeds, so that important failure-related messages aren't pushed off the screen by subsequent build timing information.

Can you make logging configurable?

We're using your maven-buildtime-extension plugin where I'm working right now - very useful!

One issue we have is that we've a large multi-module build with lots of plugins, so when it reports at the end it spams our screens. Lots of people just want to se 'BUILD SUCCESS' and only a few need to know about all the plugin timings.

Can you add a configuration parameter to allow us to turn off logging, and/or allow us to specify thresholds we might be interested in reporting? Perhaps its also possible to report how long each module takes so we'd only be interested in reporting plugins if the entire module takes more than a certain time...

Right now we're suppressing the entire plugin using a build profile so would be great to have a bit of configuration built in.

Thanks

Build time sorted by spended time

Could you add some ability to sort desceding goals by spended time?
I have a very big project and want to see most problematic items but now i need to expost data to CSV and then sort them in Excel.
For me looks that this feature will be useful.

Maven 3.2.x Compatibility

Running on 3.2.1 produced the following issue. Thanks!

constituent[39]: file:/c:/maven/conf/logging/

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.maven.executi
on.MavenExecutionRequest.isThreadConfigurationPresent()Z
at org.apache.maven.cli.ExecutionEventLogger.logStats(ExecutionEventLogg
er.java:205)

Make ExecutionTimingExecutionListener compatible with existing ExecutionListener

Jenkins injects its own ExecutionListener to extract information about the build. Since MavenExecutionRequest supports only one ExecutionListener it is currently overwritten by ExecutionTimingExecutionListener.

We could either use a delegating pattern similar to
https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyExecutionListener.java or directly use the EventSpy mechanism https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/eventspy/AbstractEventSpy.java

From what I've seen extending AbstractEventSpy is the right way to go.

using this extension removes colorized output from maven

A couple of releases ago, Maven started supporting colorized ansi output, which makes the logs very easy to read. When I use this plugin to profile the times associated with the build (love it!), I lose the colorized output (do not love it).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.