我有一个非常慢的maven构建。我想知道是否有一种方法来分析maven执行,以找出哪些是最耗时的步骤。
稍后我会想要比较旧版本(更快)的构建之间的这些时间,因此理想情况下它们应该是可以比较/差异/绘制的格式。
答案 0 :(得分:5)
这是最快捷的方式:
export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS \
-Dorg.slf4j.simpleLogger.showDateTime=true"
mvn test
结果
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 ---
的信息
答案 1 :(得分:4)
开箱即用的解决方案是takari maven profiler: https://github.com/takari/maven-profiler
其页面的示例输出:
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
答案 2 :(得分:1)
此功能已包含在Maven3中。这是相关的票证:https://issues.apache.org/jira/browse/MNG-4639
如果您需要对Maven2执行相同操作,我建议您构建自己的插件,该插件可以挂钩到执行的所有阶段(或者只是您需要跟踪的插件)。
答案 3 :(得分:0)
我在这里创建一个要点:https://gist.github.com/boly38/7316378
这是关于如何记录某些maven lifecycle steps的日期时间的示例。
当然,您可以调整此示例以设置自己的输出格式(并将其绘制成图形......)。
希望这个帮助
提取:
<profile>
<id>stats</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>log_validate</id>
<phase>validate</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
<tstamp><format property="stepTstamp" pattern="dd-HH:mm:ss" locale="en,US" /></tstamp>
<echo file="stats.log" append="true"
message="${line.separator}${line.separator}${stepTstamp} validate${line.separator}"/>
</tasks>
</configuration>
</execution>
(...)
<execution>
<id>log_process_sources</id>
<phase>process-sources</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
<tstamp><format property="stepTstamp" pattern="dd-HH:mm:ss" locale="en,US" /></tstamp>
<echo file="stats.log" append="true"
message="${stepTstamp} process-sources${line.separator}"/>
</tasks>
</configuration>
</execution>
(...)
答案 4 :(得分:0)
https://github.com/jcgay/maven-profiler是一个类似的便利工具。它易于设置和使用。 (在核心Maven中有类似的东西或者EventSpy takari / maven-profiler作为一个选项肯定会很整洁;在https://issues.apache.org/jira/browse/MNG-4639中评论..)