Fahad Siddiqui
Fahad Siddiqui

Reputation: 1849

Is there any way to speedup maven build?

I have a project containing multiple maven modules. Due to so much dependencies among these modules I have to build whole project rather building some of the modules that I need to test. It takes a lot of time to build.

Is there any way to speedup this process in by running maven build on my server through shell command?

I have tried multiple variations of -T tag in mvn arguments but none of them helped to speedup building process.

Help? Anybody?

Upvotes: 2

Views: 2135

Answers (3)

user431640
user431640

Reputation: 61

If the goal is to speedup CI server build, but only rebuilding modules affected by the changes, hashver-maven-plugin is intended to solve this: https://github.com/avodonosov/hashver-maven-plugin

Upvotes: 0

eisbaer
eisbaer

Reputation: 338

One thing you could do is read the output from the maven log using -X or -debug and go through and add the following for anything that is being executed, but is not needed:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>none</phase>
        </execution>   
    </executions> 
</plugin>

for instance, you could skip the testCompile phase that runs by adding this execution line from above to your pom.

before in the log:

[DEBUG] Goal:          org.apache.maven.plugins:maven-compiler-plugin:3.2:testCompile (default-testCompile)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>

after in the log: it doesn't show up at all.

be careful when doing this not to remove anything important.

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328594

Maven isn't magic. If your build process is slow, then you have to analyze it, determine which parts are slow and then figure out ways to enhance the situation.

The first step is to look at the times that Maven reports at the end of the build. Here you can see which modules need most of the time.

A few common causes why the build is slow:

  • People prefer integration or end-to-end tests over unit tests. Solution: Write better tests or disable slow tests on the desktop - run them over night on a CI server.
  • Huge code base. Solution: Split up.
  • You can build a single module and all its dependencies. That will skip all modules which aren't included in the one module. Solution: Maven Modules + Building a Single Specific Module

Upvotes: 3

Related Questions