Home > OS >  Gradle - Write Task Output Into A File
Gradle - Write Task Output Into A File

Time:12-20

I am working with Gradle 7.1, and I am trying to write some of the tasks resuts into a file.
Specifically, I would like to write the output of dependencies task into a file after each jar task execution.
Looking for some solutions, I understand that at first I need to have jar.finalizedBy(dependencies) in order fot it to run.
However, I can't find how to redirect the dependencies's specific output into a file. All the solutions that I have found discuss Exec tasks, which dependencies isn't.
I am looking for somehing like dependencies.doFirst(///REDIRECT HERE).

CodePudding user response:

You can make dependencies task write to file by attaching a StandardOutputListener:

tasks.named('dependencies').configure {
    it.logging.addStandardOutputListener(new StandardOutputListener() {
        @Override
        void onOutput(CharSequence charSequence) {
            project.file("$buildDir/dependencies_task_output.txt") << charSequence
        }
    })
}

This can also be done with any other Gradle task.

  • Related