When you build with maven on a multicore / multi-CPU machine it would often be possible to build different subprojects in parallel. Is there a way to do this with maven? Is there a plugin for this / whatever?
当您在多核/多cpu机器上与maven一起构建时,常常可以并行地构建不同的子项目。有办法用maven实现这一点吗?这有插件吗?
4 个解决方案
#1
171
Maven 3 (as of beta 1) now supports parallel builds as an experimental feature.
Maven 3(从beta 1开始)现在支持作为实验特性的并行构建。
For example,
例如,
mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core
Full documentation can be found on the Maven wiki.
可以在Maven wiki上找到完整的文档。
https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3
https://cwiki.apache.org/confluence/display/MAVEN/Parallel + +在+ Maven构建+ 3
#2
12
Some of the CI build applications (e.g. hudson) can build multiple maven projects at the same time (and even on multiple machines).
一些CI构建应用程序(例如hudson)可以同时构建多个maven项目(甚至在多台机器上)。
Support for this in maven 'standalone' would also be nice, a quick look through the maven issue tracker gave me: http://jira.codehaus.org/browse/MNG-3004
在maven“独立”中支持这一点也不错,快速浏览一下maven问题跟踪器,我得到了http://jira.codehaus.org/browse/MNG-3004
#3
3
The suggested solutions are great but I wanted to add something to the answers here regarding the test stability during parallel builds.
建议的解决方案很棒,但是我想在这里添加一些关于并行构建期间测试稳定性的答案。
So, when Maven parallel build is used:
因此,使用Maven并行构建时:
mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core
Some issues with tests can appear. Note any behavior in tests which is different between serial and parallel test execution. Most of the times it happens do to unproper test isolation resource-wise.
可能会出现一些与测试有关的问题。注意测试中的任何行为,它们在串行和并行测试执行之间是不同的。大多数情况下,在资源方面测试隔离是不适当的。
For example, test1 manipulate db entry with key 12345, which is hardcoded and test2 uses the same entry! It can't be good...
例如,test1使用密钥12345操作db条目,它是硬编码的,test2使用相同的条目!它不能很好…
It's a situation that should be considered in the first place, but sometime it's forgotten and could lead to different problems once the switch to parallel maven build is made.
这是一种应该首先考虑的情况,但有时会被遗忘,一旦切换到并行maven构建,可能会导致不同的问题。
In case that happens, and you still want to use the parallel execution at least in some of the occasions, you can (of course, besides trying to fix the test and make them properly isolated) to disable Maven test runs using -DskipTests argument:
如果发生这种情况,并且您仍然希望至少在某些情况下使用并行执行,那么您可以(当然,除了尝试修复测试并使其适当隔离之外)使用-DskipTests参数禁用Maven测试运行:
mvn clean install -T 4 -DskipTests
#4
0
If you came to this question looking to sort out your build server and you're not using one that deals with maven natively the magic flag you are looking for is this:
如果你问这个问题想要分类你的构建服务器而你没有使用一个本地处理maven的服务器那么你要找的魔法标志是:
-Dmaven.repo.local=someNoneGlobalDir
do that for each one of your builds and you can let them run all at the same time rather than having everything that uses maven in a queue!
对每个构建都这样做,您可以让它们同时运行,而不是让所有使用maven的东西都在队列中!
#1
171
Maven 3 (as of beta 1) now supports parallel builds as an experimental feature.
Maven 3(从beta 1开始)现在支持作为实验特性的并行构建。
For example,
例如,
mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core
Full documentation can be found on the Maven wiki.
可以在Maven wiki上找到完整的文档。
https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3
https://cwiki.apache.org/confluence/display/MAVEN/Parallel + +在+ Maven构建+ 3
#2
12
Some of the CI build applications (e.g. hudson) can build multiple maven projects at the same time (and even on multiple machines).
一些CI构建应用程序(例如hudson)可以同时构建多个maven项目(甚至在多台机器上)。
Support for this in maven 'standalone' would also be nice, a quick look through the maven issue tracker gave me: http://jira.codehaus.org/browse/MNG-3004
在maven“独立”中支持这一点也不错,快速浏览一下maven问题跟踪器,我得到了http://jira.codehaus.org/browse/MNG-3004
#3
3
The suggested solutions are great but I wanted to add something to the answers here regarding the test stability during parallel builds.
建议的解决方案很棒,但是我想在这里添加一些关于并行构建期间测试稳定性的答案。
So, when Maven parallel build is used:
因此,使用Maven并行构建时:
mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core
Some issues with tests can appear. Note any behavior in tests which is different between serial and parallel test execution. Most of the times it happens do to unproper test isolation resource-wise.
可能会出现一些与测试有关的问题。注意测试中的任何行为,它们在串行和并行测试执行之间是不同的。大多数情况下,在资源方面测试隔离是不适当的。
For example, test1 manipulate db entry with key 12345, which is hardcoded and test2 uses the same entry! It can't be good...
例如,test1使用密钥12345操作db条目,它是硬编码的,test2使用相同的条目!它不能很好…
It's a situation that should be considered in the first place, but sometime it's forgotten and could lead to different problems once the switch to parallel maven build is made.
这是一种应该首先考虑的情况,但有时会被遗忘,一旦切换到并行maven构建,可能会导致不同的问题。
In case that happens, and you still want to use the parallel execution at least in some of the occasions, you can (of course, besides trying to fix the test and make them properly isolated) to disable Maven test runs using -DskipTests argument:
如果发生这种情况,并且您仍然希望至少在某些情况下使用并行执行,那么您可以(当然,除了尝试修复测试并使其适当隔离之外)使用-DskipTests参数禁用Maven测试运行:
mvn clean install -T 4 -DskipTests
#4
0
If you came to this question looking to sort out your build server and you're not using one that deals with maven natively the magic flag you are looking for is this:
如果你问这个问题想要分类你的构建服务器而你没有使用一个本地处理maven的服务器那么你要找的魔法标志是:
-Dmaven.repo.local=someNoneGlobalDir
do that for each one of your builds and you can let them run all at the same time rather than having everything that uses maven in a queue!
对每个构建都这样做,您可以让它们同时运行,而不是让所有使用maven的东西都在队列中!