How can I list the remote repositories used in gradle project by parsing build.gradle from a maven project.Using aether for a maven project I was able to get the dependencies looking for something similar to aether that can be used on gradle projects to get the dependencies, remote repositories used in the project.
1 Answers
build.gradle
is not really parsed, but interpreted, because each Gradle script is a Groovy script. Of course you could try to parse the repositories
or the dependencies
closure, but you could never be sure, that other parts of the script or even other scripts like initialization scripts add repositories or dependencies behind your back.
I would recommend to write tasks that collect the repositories or dependencies and write them in a parseable format / notation like CSV, JSON or XML. If you need to reuse the functionality, you could even wrap these tasks in a plugin.
To iterate over repositories, I can refer to this similar question.
For dependencies, you have two possibilities: Either write a task on your own, like for the repositories, or use the existing type DependencyReportTask
and its outputFile
property. Then you would have to find a way to parse the report format.

- 1
- 1

- 13,515
- 7
- 46
- 62
-
Thanks for the info. My case is that I just have build.gradle(which is out of the gradle project context) file and I need to collect the remote repositories from which gradle is trying to resolve the dependencies. – syk_coder May 10 '17 at 06:57