Unwanted artifact version resolution against jcenter.bintray.com


(Lars Ködderitzsch) #1

Hi there,
we use an inhouse hosted Artifactory to control third party artifact usage for our products.

Therefor in our gradle setup we redefine the maven and jcenter repository to run against our internal Artifactory server.

init.gradle:

allprojects {
    buildscript {
        repositories {
           mavenLocal()
           maven {
               url "http://***/artifactory/libs/"
           }
           jcenter {
               url "http://***/artifactory/libs/"
           }
       }
   }
   repositories {
        mavenLocal()
        maven {
            url "http://***/artifactory/libs/"
        }
        jcenter {
            url "http://***/artifactory/libs/"
        }
   }

}

Functionally it is all fine and working, but when running gradle with --debug we’re still seeing requests during artifact version resolution being made to jcenter.bintray.com.
This is undesired, because those request are also made for our own internal artifacts.

How can we prevent those requests?

Thanks,
Lars

Stack trace during artifact resolution:

Caused by: org.gradle.api.resources.ResourceException: Failed to list versions for ***.
    at org.gradle.api.internal.artifacts.repositories.resolver.ChainedVersionLister$1.visit(ChainedVersionLister.java:55)
    at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.listVersionsForAllPatterns(ExternalResourceResolver.java:165)
    at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.doListModuleVersions(ExternalResourceResolver.java:154)
    at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.access$100(ExternalResourceResolver.java:83)
    at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.listModuleVersions(ExternalResourceResolver.java:449)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockReleasingModuleComponentsRepository$LockReleasingRepositoryAccess$1.run(CacheLockReleasingModuleComponentsRepository.java:68)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:242)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:313)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:114)
    at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.longRunningOperation(DefaultCacheFactory.java:179)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.longRunningOperation(DefaultCacheLockingManager.java:56)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockReleasingModuleComponentsRepository$LockReleasingRepositoryAccess.listModuleVersions(CacheLockReleasingModuleComponentsRepository.java:66)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.listModuleVersions(CachingModuleComponentRepository.java:297)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.BaseModuleComponentRepositoryAccess.listModuleVersions(BaseModuleComponentRepositoryAccess.java:44)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedModuleComponentRepository$CachedAccess.listModuleVersions(InMemoryCachedModuleComponentRepository.java:74)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.listModuleVersions(ErrorHandlingModuleComponentRepository.java:85)
    ... 134 more
Caused by: org.gradle.api.resources.ResourceException: Unable to load Maven meta-data from https://jcenter.bintray.com/****/maven-metadata.xml.
    at org.gradle.api.internal.artifacts.repositories.resolver.MavenMetadataLoader.load(MavenMetadataLoader.java:51)
    at org.gradle.api.internal.artifacts.repositories.resolver.MavenVersionLister$1.visit(MavenVersionLister.java:47)
    at org.gradle.api.internal.artifacts.repositories.resolver.ChainedVersionLister$1.visit(ChainedVersionLister.java:47)
    ... 150 more
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://jcenter.bintray.com/****/maven-metadata.xml'.
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:72)
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performRawGet(HttpClientHelper.java:58)
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performGet(HttpClientHelper.java:62)
    at org.gradle.internal.resource.transport.http.HttpResourceAccessor.openResource(HttpResourceAccessor.java:51)
    at org.gradle.internal.resource.transport.http.HttpResourceAccessor.openResource(HttpResourceAccessor.java:34)
    at org.gradle.internal.resource.transfer.DefaultExternalResourceConnector.openResource(DefaultExternalResourceConnector.java:56)
    at org.gradle.internal.resource.transport.DefaultExternalResourceRepository.getResource(DefaultExternalResourceRepository.java:63)
    at org.gradle.api.internal.artifacts.repositories.resolver.MavenMetadataLoader.parseMavenMetadataInfo(MavenMetadataLoader.java:57)
    at org.gradle.api.internal.artifacts.repositories.resolver.MavenMetadataLoader.load(MavenMetadataLoader.java:47)
    ... 152 more
Caused by: java.net.UnknownHostException: jcenter.bintray.com
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:111)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performHttpRequest(HttpClientHelper.java:102)
    at org.gradle.internal.resource.transport.http.HttpClientHelper.executeGetOrHead(HttpClientHelper.java:79)
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:70)
    ... 160 more

(James Justinic) #2

You do not need to “redefine” the repositories available using the helper methods in RepositoryHandler. Those repositories are only used if you call them. Instead, your repository setup should just include the configuration of the repositories that you do want to use.

mavenLocal() is adding the standard configuration to use your local maven repository.

maven { url "http://***/artifactory/libs/" } configures a maven format repository (this is all you need for your artifactory repository. Note this is not the same as mavenCentral()).

jcenter { url "http://***/artifactory/libs/" } is adding the standard configuration for the jcenter() repository. The closure is not reconfiguring it as you expect. You should remove this.


(Lars Ködderitzsch) #3

Thank you, James.
I did as you suggested and removed the “jcenter-override”. However, I am still seeing the requests to jcenter.bintray.com.

It seems either gradle itself or some 3rd-party plugin we’re using is adding the jcenter repository, it’s certainly not in our in-house plugins or build scripts.
I am trying to hunt this down…

Meanwhile I’ve worked around by adding this to our repositories configuration (suggested here: http://stackoverflow.com/questions/27056733/change-gradle-mavencentral-url-to-my-repo):

    repositories {
        all { ArtifactRepository repo ->
            if ((repo instanceof MavenArtifactRepository) 
                && !repo.url.toString().startsWith(System.properties["artifactoryUrl"])
                && !repo.url.toString().startsWith("file:")) {
                project.logger.warn "Repository \"${repo.url}\" has been removed."
                remove repo
            } 
        }

The warning is indeed being printed, proofing that something is adding the jcenter repo - alongside with a nice performance improvement.


(Lars Ködderitzsch) #4

Ok, by patching gradles DefaultRepositoryHandler#jcenter() method and throwing a RuntimeException there, I was able to track down the issue.

Turns out we were missing a configuration setting in the asciidoctor plugin, which led to this plugin adding the jcenter repo (see https://github.com/asciidoctor/asciidoctor-gradle-plugin/blob/development/src/main/groovy/org/asciidoctor/gradle/AsciidoctorPlugin.groovy line 46).

By adding this to our build setup the jcenter usage stopped:

asciidoctorj {
  noDefaultRepositories = true
}