Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Maven project effectively and fast

Tags:

java

maven

I have a maven project with 13 sub modules. I have two questions how to optimize the build process:

  1. I want to compile the Java code only for x86-64 server. How I con configure Maven to do this?
  2. I have a server with 4 CPU cores. Is it possible to use multi-threading for compiling the code?
like image 681
user1285928 Avatar asked Jul 24 '12 11:07

user1285928


3 Answers

2) mvn package -T 2C will build with 2 Threads per CPU core

like image 119
Korgen Avatar answered Oct 30 '22 18:10

Korgen


  1. I want to compile the Java code only for x86-64 server. How I con configure Maven to do this?

Java is cross platform. You can't make it compile for only x86-64.

.2. I have a server with 4 CPU cores. Is it possible to use multi-threading for compiling the code?

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.

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.

like image 11
Peter Lawrey Avatar answered Oct 30 '22 17:10

Peter Lawrey


  1. Maven invokes standard javac.
  2. Yes, it is possible, see Parallel builds in Maven 3
like image 5
Andrew Logvinov Avatar answered Oct 30 '22 19:10

Andrew Logvinov