Gradle seems to be slow to resolve dependencies from Maven Nexus Repository Running with --debug shows NullPointerException

I have a Gradle project setup which has the following repositories configured:

repositories {
        mavenLocal()
        mavenCentral()
        maven {
             url $nexusUrl
        }

I noticed that this seems to be quite slow when attempting to retrieve artefacts which are hosted in our internal nexus repo.

After running with --debug I noticed multiple Stacktraces like the following could this be related to the issue I am seeing or is this a Red herring?

19:55:18.671 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver] Discarding resolve failure.
java.lang.NullPointerException
 at org.gradle.api.internal.artifacts.repositories.resolver.MavenLocalResolver.isOrphanedPom(MavenLocalResolver.java:49)
 at org.gradle.api.internal.artifacts.repositories.resolver.MavenLocalResolver.findMetaDataArtifact(MavenLocalResolver.java:42)
 at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.resolveStaticDependency(ExternalResourceResolver.java:165)
 at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.getDependency(MavenResolver.java:83)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LocalModuleVersionRepository.getLocalDependency(LocalModuleVersionRepository.java:44)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.CachedRepository.getLocalDependency(CachedRepository.java:67)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver$RepositoryResolveState$LocalModuleAccess.getDependency(RepositoryChainDependencyResolver.java:206)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver$StaticVersionRepositoryResolveState.process(RepositoryChainDependencyResolver.java:228)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver$RepositoryResolveState.resolve(RepositoryChainDependencyResolver.java:179)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.findLatestModule(RepositoryChainDependencyResolver.java:110)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.findLatestModule(RepositoryChainDependencyResolver.java:86)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver.resolve(RepositoryChainDependencyResolver.java:61)
 at org.gradle.api.internal.artifacts.ivyservice.clientmodule.ClientModuleResolver.resolve(ClientModuleResolver.java:35)
 at org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectDependencyResolver.resolve(ProjectDependencyResolver.java:49)
 at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$AbstractVersionResolveResult.resolve(LazyDependencyToModuleResolver.java:69)
 at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ModuleVersionResolveState.resolve(DependencyGraphBuilder.java:655)
 at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ModuleVersionResolveState.getMetaData(DependencyGraphBuilder.java:666)
 at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.calculateTargetConfigurations(DependencyGraphBuilder.java:340)
 at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.attachToTargetConfigurations(DependencyGraphBuilder.java:314)
 at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:130)

Looks like some problem related to the local Maven repo. Which Gradle version are you running? Can you reproduce this with the latest Gradle version, and if so, can you help us reproduce it? If upgrading Gradle doesn’t solve the problem, here are some other things you can try:

  • Only ever use ‘mavenLocal()’ if the Gradle build needs to consume artifacts created by a local Maven build. Otherwise, get rid of it. This will make your build faster (no need to search the local Maven repo, which can be huge), more repeatable (no more “works for me” because developers have different artifacts in their local Maven repos), and won’t cause any additional downloads. * Wipe out your local Maven repo.

Thanks for your quick response Peter.

Removing mavenLocal seems to have sped things up quite a bit.

On first thoughts this seems counter intuitive in that I would expect that accessing a local cache would speed things up but given your explanation around indexing the different repository structure between Maven & Gradle this makes more sense.

Perhaps it would make sense to include your comments above in the Gradle doco i.e.

Only ever use mavenLocal() if the Gradle build needs to consume artifacts created by a local Maven build. Otherwise, get rid of it. This will make your build faster (no need to search the local Maven repo, which can be huge), more repeatable (no more “works for me” because developers have different artifacts in their local Maven repos), and won’t cause any additional downloads.