Gathering dependency jars recursively in Gradle plugin

I’m writing a Gradle plugin in Java for a compiler that needs paths to all compiled .class files and dependency jars. I figured that the compiled sources are located at classes child of project.getBuildDir(), but I’m struggling how to get absolute paths to all dependency jars. As you might guess, I also need their dependencies, so basically I have to go through the whole dependency tree. I tried using project.getConfigurations().getByName("compile").getAllDependencies(), but I’m not sure if that’s the correct way to go or if it even allows to get the dependencies recursively. Can you point me to the correct way of accessing absolute paths of all project’s dependencies?

Configurations already implement the FileTree interface. If they are asked for their files, they will resolve all dependencies. So you can just pass the configuration as an input to your other task.

Don’t rely on any hardcoded paths. The output of a sourceSet can be obtained by calling e.g. sourceSets.main.output. This will give you the compiled classes and resources.

Thanks, I missed that part about FileTree extension. I also refactored the output related code. It works as expected.