Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle JavaExec StandardOutput to include Java command

Tags:

gradle

Is it possible to add in the java command to the standardOutput stream on a JavaExec command in Gradle?

Ie

task importSitesDef(dependsOn: init, type: JavaExec) {
    main = 'com.x'
    classpath = configurations.runE
    standardOutput = new FileOutputStream(standardLog, true)
}

Will log the output but I want to see java com.x -cp ... in the file too before the input.

This is due to using the same output stream/file for multiple tasks and its very hard to tell where the output from one task finished before another one starts.

like image 231
IanWatson Avatar asked Aug 05 '26 04:08

IanWatson


1 Answers

I know this is an old question but all I did to get the Java command used was to get the output of the JavaExec commandLine method and join it's elements, like so:-

commandLine.collect().join(' ')

Then output it.

like image 129
Ross Drew Avatar answered Aug 06 '26 19:08

Ross Drew