Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I speed up Gradle dependency resolution or generally improve performance?

I'm converting a very large build over from Maven. There were a number of BOMs which I've converted to dependency lists. I'm also using the Spring Dependency management plug-in.

Problem is that dependency management is taking forever. Note that it seems to take way too long even when I use --offline. I've also just read that using allprojects {} and subprojects{} causes parallelism to fail. Clearly I need something that provides similar functionality, though. The objective of this migration in the first place was to improve performance but I don't think it's any better so far. I need to know:

How can I set up my dependency lists in configuration phase, do it only once and have it scoped so that the information is available to all projects? Is there an example of a plug-in that does this? Of course, it would have to work with parallelism.

Is there anything I need to do with the Spring dependency management plugin that will improve performance?

Right now, build time is roughly 25 minutes (running offline) and I'm on a half-way decent 8 core box. That's with the daemon running and no unit or integration testing. :-/

like image 699
user447607 Avatar asked Oct 31 '22 10:10

user447607


1 Answers

It's hard to say without knowing more about your environment or your set up. But some general rules:

  1. Are you sure it is the dependency resolution that is the problem, use --profile to get more information. (see docs)

  2. Make sure you only have one repository to look from, preferably close to you and fast. We normally set up a proxy in our Nexus, that way we let Nexus cache for the whole department. For each new repository, Gradle looks for all versions there as well.

  3. Make sure your Gradle cache is fast (think local SSD vs NFS mounted old disk). Otherwise move your $GRADLE_USER_HOME to another local place.

  4. Adding DependencyResolutionListener may give you more information regarding what may be the bottleneck.

Try adding the following to the start of your build.gradle:

gradle.addListener(new DependencyResolutionListener() {
    ThreadLocal<Long> start = new ThreadLocal<>()
    @Override
    void beforeResolve(ResolvableDependencies dependencies) {
        start.set(System.nanoTime())
    }

    @Override
    void afterResolve(ResolvableDependencies dependencies) {
        long stop  = System.nanoTime() - start.get()
        println "resolving $dependencies.resolutionResult.root.moduleVersion of configuration $dependencies.name (${stop/1000000} ms)"
    }
})
like image 148
Jocce Nilsson Avatar answered Nov 08 '22 09:11

Jocce Nilsson