Identify ResolvedRepository Details


(Siva Jeganathan) #1


I have a gradle file with list of dependencies. I also got 3-5 repositories.
I want to map/print dependency with repository details. Any suggestions ?

for example:

repositories {


org.apache:ant:10.0 ==> jcenter()

(Chris Doré) #2

The information about which repository a dependency came from is not available, at least not in a way I’ve been able to find. I asked a similar question a while back, but in my case I was looking for the URL. I’m afraid you’re probably out of luck, without looking at modifying Gradle’s source

However, depending how bad you want/need this, you could create subprojects, each with one of the repositories, then add the dependencies to a configuration in those projects and enumerate Configuration#getIncoming()#getResolutionResult()#getAllDependencies() looking for instances of ResolvedDependencyResult.

repositories {
configurations {
dependencies {
    xyz ...
task showDeps {
    doLast {
        println "Resolvable deps in jcenter():"
        println { dep ->
            dep instanceof ResolvedDependencyResult
        }.join( '\n    ')

(Siva Jeganathan) #3

Thanks Chris,
I will try your inputs…
I think there are more points to consider here. The gradle cache , local repository access, etc.

Another way, I am thinking is to develop a plugin which does the following :
#1. Get list of Maven / External repositories as specified in build file (order) - I am trying to find the API. Help me if you can.
#2. Search each Repo for the artifact and display the first Match.

I am also trying to understand how gradle prints the dependency resolution in its debug log. Any pointers ?


(Chris Doré) #4

I believe the RepositoryHandler object that backs repositories is ordered.

println repositories.collect {"${} - ${it.url}"}.join('\n')

See if that follows the ordering when you move things around.

(Siva Jeganathan) #5

Chris Your idea seems promising. But I am trying to understand how I can create sub-project on the fly and remove them.

(Chris Doré) #6

You can create virtual/dynamic subprojects using settings.gradle (which you could write a settings plugin for if you’d like), but there’s no way to remove them during the execution of the build (and you probably don’t need to in my opinion).
I’ve written such a settings plugin for a deployment tool that needed to resolve dependencies from promotion-level specific repositories. I’ll reply with some examples once I have some time to “public-ify” it.

(Siva Jeganathan) #7

I tried with ProjectBuilder.builder().build() to get a project for now.
I added the repo to dummy project using
project.getRepositories().add(0, repoFromParent);
Hitting below error message. Is there any step I need to follow to convert MavenRepository to ResolutionAwareRepository?

Caused by: java.lang.ClassCastException: Failed to cast object org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated@7885611b of type org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated to target type org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository.

(Siva Jeganathan) #8

I am able to complete this. I will try to publish this as a separate plugin if possible.