Resolve dependencies from build.gradle through java calls?

Hello guys, I am working on a side project that depends (not sure if that’ll be the right term for this) on a main project. The main project builds with gradle and contains many modules with build.gradle files that contain dependencies similar to:

dependencies {
compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"

What my side project needs to do is to take in the above line and resolve/retrieve the dependency to an external directory, the key is I want to try not to add any code into the main project (putting files into the same directory is okay, in case I need to make something like other.gradle).

I am thinking of 2 different approaches:

  1. Create a task and run it through gradle.
  2. Use gradle api through java to call the resolver.

I did the first option so far, I have an other.gradle with a copy task from configurations.compile to my directory. But I had to import this gradle file into the main project that caused changes in the main project’s gradle file, which is something the boss do not want.

As for option 2, I was wondering if I can call gradle’s ivy apis with the contents of the above code to resolve the dependency this way.

Thanks guys!

Reading between the lines… are you saying you have a main project that you don’t want to touch, but you want to extract all dependency information from it?

yes that is correct. I am hoping to populate a directory with all the dependency jars from the main project.