Java maven 构建需要太长时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21090915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The maven build takes too long
提问by Nabil
The global build of our application (30 Maven modules) is taking too much time (15 minutes). This includes units and integration tests. The majority of the time is consumed by the integrations tests (60%).
我们应用程序的全局构建(30 个 Maven 模块)花费了太多时间(15 分钟)。这包括单元和集成测试。大部分时间用于集成测试 (60%)。
Our tech stack comprises of Spring, Spring MVC, Spring Batchetc. and Maven. Our developers are not motivated to keep this practice (Build All before commit)
我们的技术栈包括Spring、Spring MVC、Spring Batch等和Maven。我们的开发人员没有动力保持这种做法(提交前全部构建)
Since I want to improve the build time I am suggesting these scenarios:
由于我想缩短构建时间,因此我建议使用以下场景:
- Parallel build :
mvn -T 1C
is not going to work as this consumes all resources of developer machine which prevents the developer from doing other things. - Organize module by profile (
front, batch, connector, commons
) is not going to work either as our modules are inter-dependent and we must do the build all.
- 并行构建:
mvn -T 1C
不会工作,因为这会消耗开发人员机器的所有资源,从而阻止开发人员做其他事情。 - 按配置文件组织模块 (
front, batch, connector, commons
) 也不起作用,因为我们的模块是相互依赖的,我们必须完成所有.
Do you have some suggestions to improve the build time of large projects?
您有什么建议可以改善大型项目的构建时间吗?
Thanks in advance.
提前致谢。
回答by Tim B
Have a build server that automatically does a full build and run the tests once someone checks in. If the build or tests fail immediately flag it in some suitably prominent way including emailing the person who did the check in.
拥有一个构建服务器,它会在有人签入后自动进行完整构建并运行测试。如果构建或测试失败,请立即以某种适当的显着方式标记它,包括向进行签入的人发送电子邮件。
回答by haraldK
Don't run the integration tests in the normal profile, let the developers check in after running unit tests only.
不要在普通配置文件中运行集成测试,让开发人员只在运行单元测试后签入。
Run integration tests on a separate server (a build server or continuous integration server, like Jenkins or similar). Have the build server email the developers that checked in bad code.
在单独的服务器(构建服务器或持续集成服务器,如 Jenkins 或类似服务器)上运行集成测试。让构建服务器向签入错误代码的开发人员发送电子邮件。
In our work office, we also have big screens showing green/yellow/red flags for each module, so everyone can see if a module is unstable (and who has checked in since the last stable build).
在我们的办公室,我们也有大屏幕显示每个模块的绿色/黄色/红色标志,因此每个人都可以看到模块是否不稳定(以及自上次稳定版本以来谁签入)。
回答by Puce
The pricipal time is consumed by the integrations tests (60%).
集成测试消耗了主要时间 (60%)。
Typically you don't want to run integration-tests during a build on developer machines. Just exclude them. But make sure you run them on your continuous integration server.
通常,您不想在开发人员机器上的构建期间运行集成测试。只是排除它们。但请确保在持续集成服务器上运行它们。
回答by Sinto
Adjust memory configurations to optimum for eg: add this line to mvn.bat set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m
Clean phase of mvn normally deletes target folder. Instead if we are renaming target folder the cleaning phase will be much faster.
-Dmaven.test.skip=true will skip the test execution.
Add -Denforcer.skip=true to mvn command line argument (This is enforcing versions of maven, jdk etc ,we can skip it after initial runs)
Disable non-critical operations during build phase: Analysis, javadoc generation, source packaging. This will save huge time.
Spawnig new process also helps in time improvement -Dmaven.junit.fork=true (fork the junit tests into a new process) -Dmaven.compile.fork=true (forks the compilation)
将内存配置调整为最佳,例如:将此行添加到 mvn.bat set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m
mvn 的清理阶段通常会删除目标文件夹。相反,如果我们重命名目标文件夹,清理阶段会快得多。
-Dmaven.test.skip=true 将跳过测试执行。
将 -Denforcer.skip=true 添加到 mvn 命令行参数(这是强制执行的 maven、jdk 等版本,我们可以在初始运行后跳过它)
在构建阶段禁用非关键操作:分析、javadoc 生成、源代码打包。这将节省大量时间。
Spawnig 新进程也有助于时间改进 -Dmaven.junit.fork=true(将 junit 测试分叉到新进程中) -Dmaven.compile.fork=true(分叉编译)
Hope it helps.
希望能帮助到你。
回答by vitfo
So our developers are not motivated to keep this practice ... ... we consume all ressources of developer machine so during the build the developer cannot do any things
所以我们的开发者没有动力保持这种做法……我们消耗了开发者机器的所有资源,所以在构建过程中开发者不能做任何事情
If the main reason why developers do not want to build all before commitis that during the maven build their computer is useless (due to the maven using all available resources), let them specify how much resources maven should use.
如果开发人员不想在提交前构建所有的主要原因是在 maven 构建期间他们的计算机没有用(由于 maven 使用所有可用资源),让他们指定 maven 应该使用多少资源。
Example (using Windows cmd), instead of:
示例(使用 Windows cmd),而不是:
mvn clean package
you can use:
您可以使用:
start /affinity 3 mvn clean package
In this case maven will use 2 cpu cores (I have 8 cpu cores) so during the maven build lifecycle I can still work on my machine.
在这种情况下,maven 将使用 2 个 cpu 内核(我有 8 个 cpu 内核),因此在 maven 构建生命周期中,我仍然可以在我的机器上工作。
The pricipal time is consumed by the integrations tests (60%)
集成测试消耗的主要时间 (60%)
I would say that tests are important but you can save some time skipping tests:
我会说测试很重要,但您可以节省一些时间跳过测试:
mvn clean package -DskipTests
More info about processor affinity could be found here: http://www.techrepublic.com/blog/windows-and-office/change-the-processor-affinity-setting-in-windows-7-to-gain-a-performance-edge/
可以在此处找到有关处理器关联的更多信息:http: //www.techrepublic.com/blog/windows-and-office/change-the-processor-affinity-setting-in-windows-7-to-gain-a-性能优势/