Getting dependencies using Gradle Tooling


(Alex Soto) #1

Hello, I would like to get all dependencies defined in a gradle file programmatically from a Java program?

I would like to get as String[] the list of dependencies used in a project. Something like gradlew dependencies but without having to parse the strings.

Thank you very much.


(Cédric Champeau) #2

I think you could use the tooling API for this. Probably the easiest way is to get an EclipseModel of your build. In particular, look at this sample: https://github.com/melix/gradle/blob/38e0df22ecff6c894f5c3eeecb94106e2ba557ff/subprojects/docs/src/samples/toolingApi/eclipse/src/main/java/org/gradle/sample/Main.java#L28-L28


(Alex Soto) #3

Yes I noticed this, but if I am using IntelliJ then probably I need to use the IntelliJModel and my question is what’s happening when you are not using any IDE. For example in your CI system where no IDE files are present (if you have configured .gitignore accordantly)


(Cédric Champeau) #4

It is independent from an IDE. You can retrieve an EclipseModel even in CI. EclipseModel is used to create a model that is suitable for use in Eclipse, so AFAIU it should be suitable for you too. Or you can use a totally custom model.


(Alex Soto) #5

Ok, thank you so much for this information :smiley: you saved my day.


(Alex Soto) #6

One thing that I have noticed is that you cannot get the scope of the dependency which is something important for Wildfly Swarm since we only need the test scope dependencies.


(Stefan Oehme) #7

If you want integration for a specific tool, it is better to build your own tooling model.