如何在多模块项目中对 Maven 目标进行计时(分析)
我们有一个包含许多子模块的庞大项目。目前完整的构建需要 30 分钟以上。
我想知道这个时间如何分布在不同的插件/目标上,例如测试、静态分析(findbugs、pmd、checkstyle 等...)
是否可以对构建进行计时以查看(在两个维度:模块和目标)最重要的地方时间花了吗?
We have a huge project with many submodules. A full build takes currently over 30mins.
I wonder how this time distributes over different plugins/goals, e.g. tests, static analysis (findbugs, pmd, checkstyle, etc ...)
Would it be possible to time the build to see where (in both dimensions: modules and goals) most time is spent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
maven-buildtime-extension 是一个 Maven 插件,可用于查看每个目标的时间:
https ://github.com/timgifford/maven-buildtime-extension
The maven-buildtime-extension is a maven plugin that can be used to see the times of each goal:
https://github.com/timgifford/maven-buildtime-extension
如果您在 CI 服务器中运行构建,例如 TeamCity 或 Jenkins(以前称为 Hudson),它将为您提供构建过程中每个步骤的时间戳,您应该能够使用这些值来确定哪些目标/项目花费了最多的时间。
我认为 Maven 没有内置任何方法可以做到这一点。事实上,在 artbristol 发布的相关问题中,有一个指向 Maven 功能请求的链接此功能。不幸的是,这个问题尚未解决,我不知道是否会添加它。
另一个潜在的解决方案是编写您自己的插件,该插件将为您提供此构建元数据。
If you run the build in a CI server like TeamCity or Jenkins (formerly Hudson), it will give you timestamps for every step in the build process and you should be able to use these values to determine which goals/projects are taking the most time.
I don't think there is any way built in to maven to do this. In fact, in the related question artbristol posted, there is a link to a Maven feature request for this functionality. Unfortunately, this issue is unresolved and I don't know if it will ever be added.
The other potential solution is to write your own plugin which would provide this build metadata for you.
我认为没有办法确定特定目标的时间安排。您可以做的是分别运行特定目标,看看它们需要多长时间。因此,不要执行“mvn install”来运行所有测试、checkstyle 等。只需执行“mvn checkstyle:checkstyle”来查看特定模块需要多长时间。
当由自动化服务器(Continum/jenkins/hudson)完成时,每次都完成所有事情是很好的,但是当您在本地构建时,有时最好能够编译。您可以做的一些事情是让静态分析目标仅在您传递特定参数或配置文件时运行。另一种选择是仅在 maven.test.skip=false 时运行它们。
如果您使用连续构建,请尝试每 4 小时或每天进行一次静态分析。
I don't think there is a way to determine the timing of particular goals. What you can do is run the particular goals separately to see how long they take. So instead of doing a "mvn install" which runs all of your tests, checkstyle, etc.. just do "mvn checkstyle:checkstyle" to see how long that takes for a particular module.
Having everything done every time is nice when its done by an automated server (continuum/jenkins/hudson) but when you are building locally, sometimes its better to be able to just compile. Some of the things you can do are have the static analysis goals ONLY run when you pass in a certain parameter or profile. Another option is to only have them ran when maven.test.skip=false.
If you are using a continuous build, try having the static analysis only done every 4 hours, or daily.