I want to copy the output from ./gradlew dependencies into a file at build time

(Hans Georg Naesheim) #1

The command ‘./gradlew dependencies --configuration _lib’ shows the dynamic versioning of my dependencies:

±-- net.group:apptest:1.0.0
±-- net.group:project2-api:2.0.+ -> 2.0.0 // here
— net.group:demo_lib:1.0.0

I’m writing a plugin and want to copy this output into a txt file. Is it possible to execute this ‘dependencies’ task as code inside a custom plugin?

Currently I have this as a Task:
File file = new File("${path}")
project.configurations._lib.each() {
But this does not show the dynamic versioning

I guess I’m asking for a lot here, but please , if possible, point me in the right direction.

(Andrew N) #2

It turns out this is pretty straightforward. The commented-out lines can restrict the report to a specific set of configurations instead of showing all of them.

task dependencyReportFile(type: DependencyReportTask) {
    outputFile = file('dependencies.txt')
    // Set configs = [project.configurations.compile]
    // setConfigurations(configs)

I figured this out by opening the Gradle source code in IntelliJ and poking around until I found AbstractReportTask.setOutputFile().

(Hans Georg Naesheim) #3

That’s perfect!

Many thanks