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.
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 ?
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.
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.