jwells131313
jwells131313

Reputation: 2404

Why does my large multi-project gradle build start up slowly?

I am on a team that has a large multi-project build (~350 modules) and we have noticed that doing an individual build (-a) still takes a large amount of time. When building the entire set of things the overhead isn't so bad, but when we do something like:

cd my/individual/project
gradle -a --configure-on-demand --daemon build

that it still takes 30-40 seconds just in the configuration phase (before it starts building anything, which we measure using the --dry-run option)

We have approximately 10 custom tasks and we are setting the inputs and outputs for those tasks but we still see this inordinately long configuration time. We are using gradle 1.10

Upvotes: 1

Views: 1576

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123950

It's hard to say from a distance. A common mistake is to do work in the configuration phase that should be done in the execution phase. Here is an example:

task myTask {
    copy {
        from ...
        to ...
    }
}

Here, the project.copy method will be called (and therefore copying will take place) every single time the task is configured, which is for every single build invocation - no matter which tasks are run! To fix this, you'd move the work into a task action:

task myTask {
    doLast {
        copy {
            from ...
            into ...
        }
    }
}

Or even better, use a predefined task type:

task myTask(type: Copy) {
    from ...
    into ...
}

Some steps you can take to find the cause(s) for performance problems:

  • Review the build
  • Run with --info, --debug, or --profile
  • Profile the build with a Java profiler

PS: Specifying inputs and outputs doesn't shorten configuration time (but likely execution time).

Upvotes: 5

Related Questions