Your question is old, but I had the same issue last days and google redirect me to your post.
In the logs I can see that Gradle uses my local artifactory, then it switches to the default remote repository:
15:04:47 2022-02-17T15:04:47.572+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Download http://artifactory.mycompany.local/artifactory/maven/org/mockito/mockito-core/maven-metadata.xml'
15:04:47 2022-02-17T15:04:47.572+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Download http://artifactory.mycompany.local/artifactory/maven/org/mockito/mockito-core/maven-metadata.xml' completed
15:04:47 2022-02-17T15:04:47.576+0100 [DEBUG] [org.gradle.api.internal.artifacts.repositories.maven.MavenMetadataLoader] parsing maven-metadata: org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource@5568cd26
15:04:47 2022-02-17T15:04:47.585+0100 [DEBUG] [org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor] Constructing external resource: https://repo.maven.apache.org/maven2/org/mockito/mockito-core/maven-metadata.xml
...
15:06:24 2022-02-17T15:06:21.731+0100 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.12.215] failed: connect timed out
...
15:06:24 2022-02-17T15:06:21.731+0100 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 2m 35s
I suppose that Gradle tries to list the versions from all repositories to define the latest version '2.+'. However the connection to the repo.maven.apache.org/maven2
repository is not possible, so the build fails in my case.
My solution was to to change the version from '2.+'
to a fixed version in the build.gradle
file, i.e.:
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.+'
to
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.28.2'