Getting dependencies using Gradle Tooling

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.

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:

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)

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.

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

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.

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