Invoking CopyDependencies-like task in gradle on a target project using tooling API

I am building a Java application which analyzes various other Java projects using Maven, Gradle and Ant. One of my tasks involves extracting dependencies of the project and storing them in a file.

For Maven, I am using the copy-dependencies task to achieve this. I am not too sure on how to achieve this using the toolingApi.

Is there anyway I can run a custom gradle task programmatically from my Java application on a target project?

Have you read the javadoc for the main classes of the tooling API?
[This one] (https://docs.gradle.org/current/javadoc/org/gradle/tooling/BuildLauncher.html) has a nice example in it.

Hi Francois,

Thank you for your reply. That link certainly helps . Thank you!.

But to achieve my goal here, I need to create a gradle task programatically and run that task in BuildLauncher. Please let me know if that is possible.

The task I am using is . Right now Its defined in build.gradle

task listJars << {
>     configurations.compile.each { File file -> println file.path + File.separator+ file.name }
> }