'Could not read standard output of command 'cmd'

I am getting the below error when I try to execute the 'clean package' maven command. Any ideas why the stream is closed ?

However, when I launch the task by itself, it works:

gradlew 41_RunUIUnittests

My task:

task 41_RunUIUnittests {

   doLast {

      def buildDir = file('../../build/build.functionaltests')

 println '\tFrom ' + buildDir   

      mavenexec {

         workingDir  buildDir
         goals       'clean', 'package'
      }
   }
}

The error:

> Task :41_RunUIUnittests
---------------------------------------------------------------------------------------
        From C:\Users\toto\git\build\build.functionaltests
Could not read standard output of command 'cmd'.
java.io.IOException: write(91) failed: stream is closed
        at org.apache.commons.io.output.ClosedOutputStream.write(ClosedOutputStream.java:47)
        at java.base/java.io.OutputStream.write(OutputStream.java:157)
        at org.apache.commons.io.output.ProxyOutputStream.write(ProxyOutputStream.java:89)
        at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:67)
        at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:53)
        at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
        at java.base/java.lang.Thread.run(Thread.java:834)

Note, I am using this plugin: gradle-maven-exec-plugin



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source