I'm using Maven 3.1.1 and the exec-maven-plugin
(1.3) in order to execute a bash script during a build job.
The bash script produces output on stdout
with echo
and printf
. I've noticed that the output of the script is not written to the maven console output instantaneously. Instead the maven console output "freezes" until it gets updated with multiple output lines of the bash script at once. I don't know what's the trigger for an update of the maven output (timeout? full output buffer?) but it's very slow.
Let's take a very simple bash script, e.g. counter.sh
:
#!/usr/bin/env bash
for i in `seq 1 1000`; do
echo $i
sleep 0.5
done
And here's my plugin configuration in the pom.xml
:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.3</version>
<executions>
<execution>
<id>execute-script</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.build.directory}/executable/counter.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
When I execute the build job with mvn clean package
, the maven output freezes at the exec-maven-plugin
and shows no progress/output until the script has completed after ~8 minutes.
When I execute another script that is running even longer, I get a block of output each ~15 minutes.
What I'm looking for is a way to see the output of the bash script instantaneously in the maven console output.
Update: Solution using maven-antrun-plugin (thanks to Ivan)
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execute-script</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec dir="${project.basedir}" executable="${project.build.directory}/executable/counter.sh" />
</target>
</configuration>
</execution>
</executions>
</plugin>
JFYI, the issue is fixed in exec-maven-plugin v 1.3.2 - http://blog.soebes.de/blog/2014/07/28/mojo-exec-maven-plugin-version-1-dot-3-2-released/
The exec-maven-plugin uses an output stream that does not flush automatically.
I think you have two options:
Maybe the 2nd option could be slower, since maven calls ant, and ant then calls your script, but is pretty easy.
As Ivan already pointed out exec-maven-plugin:1.3 doesn't automatically flush the output stream. This can lead to delayed output.
I observed that this behaviour is only present in the plugin from version 1.3 onward.
exec-maven-plugin:1.2.1 actually has the desired behaviour and flushes the output stream. So instead of using ant you could switch to an older version of exec-maven-plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With