简体   繁体   中英

The maven build takes too long

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%).

Our tech stack comprises of Spring, Spring MVC, Spring Batch etc. and Maven . Our developers are not motivated to keep this practice (Build All before commit)

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 .

Do you have some suggestions to improve the build time of large projects?

Thanks in advance.

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.

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).

  1. Adjust memory configurations to optimum for eg: add this line to mvn.bat set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m

  2. Clean phase of mvn normally deletes target folder. Instead if we are renaming target folder the cleaning phase will be much faster.

  3. -Dmaven.test.skip=true will skip the test execution.

  4. Add -Denforcer.skip=true to mvn command line argument (This is enforcing versions of maven, jdk etc ,we can skip it after initial runs)

  5. Disable non-critical operations during build phase: Analysis, javadoc generation, source packaging. This will save huge time.

  6. 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)

Hope it helps.

The pricipal time is consumed by the integrations tests (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.

拥有一个构建服务器,它会在有人签入后自动进行完整构建并运行测试。如果构建或测试失败,请立即以某种适当的显着方式标记它,包括向进行签入的人发送电子邮件。

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 commit is 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.

Example (using Windows cmd), instead of:

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.

The pricipal time is consumed by the integrations tests (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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM