java 如何高效快速的编译Maven项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11630174/
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
How to compile Maven project effectively and fast
提问by user1285928
I have a maven project with 13 sub modules. I have two questions how to optimize the build process:
我有一个包含 13 个子模块的 Maven 项目。我有两个问题如何优化构建过程:
- I want to compile the Java code only for x86-64 server. How I con configure Maven to do this?
- I have a server with 4 CPU cores. Is it possible to use multi-threading for compiling the code?
- 我只想为 x86-64 服务器编译 Java 代码。我如何配置 Maven 来做到这一点?
- 我有一台带有 4 个 CPU 内核的服务器。是否可以使用多线程来编译代码?
采纳答案by Peter Lawrey
- I want to compile the Java code only for x86-64 server. How I con configure Maven to do this?
- 我只想为 x86-64 服务器编译 Java 代码。我如何配置 Maven 来做到这一点?
Java is cross platform. You can't make it compile for only x86-64.
Java是跨平台的。你不能让它只为 x86-64 编译。
.2. I have a server with 4 CPU cores. Is it possible to use multi-threading for compiling the code?
.2. 我有一台带有 4 个 CPU 内核的服务器。是否可以使用多线程来编译代码?
The javac
is multi-threaded. It might not use all the cores you have, but that's as multi-threaded as you can make it.
的javac
是多线程。它可能不会使用您拥有的所有核心,但这是您可以做到的多线程。
As Andrew notes, you can make the build multi-threaded which causes the tests to be run concurrently (something which might break your tests) This doesn't make the compilation concurrent.
正如安德鲁指出的那样,您可以使构建成为多线程的,这会导致测试并发运行(这可能会破坏您的测试)这不会使编译并发。
回答by Korgen
2) mvn package -T 2C
will build with 2 Threads per CPU core
2)mvn package -T 2C
将构建每个 CPU 内核 2 个线程
回答by Andrew Logvinov
- Maven invokes standard
javac
. - Yes, it is possible, see Parallel builds in Maven 3
- Maven 调用标准
javac
. - 是的,有可能,请参阅Maven 3 中的并行构建
回答by FrVaBe
Some time ago I readabout this pom configuration to improve compiler performance
前段时间我读到了这个 pom 配置来提高编译器性能
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
.....
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>1.8.6</version>
</dependency>
</dependencies>
</plugin>
I did not try it but it may be interesting for you.
我没有尝试过,但它可能对你很有趣。
The explanation of this improvement can be found here.
可以在此处找到此改进的说明。
回答by radai
in addition to parallel builds (-Tn flag mentioned above) see if you can hide away all sorts of extra stuff under profiles - configure tests to be off by default, do all sorts of tagging, code analysis, distribution to remote repositories etc optionally. you could also try throwing more memory at maven (MAVEN_OPTS env. var)
除了并行构建(上面提到的 -Tn 标志),看看你是否可以隐藏配置文件下的各种额外内容 - 将测试配置为默认关闭,进行各种标记、代码分析、分发到远程存储库等。你也可以尝试在 maven (MAVEN_OPTS env.var) 上扔更多的内存