How to echo in Maven without Antrun plugin?

feder picture feder · Apr 2, 2013 · Viewed 11k times · Source

How can I print to the console while executing a mvn command (in a phase/goal), but not using Maven Antrun plugin?

Why I reject Antrun solutions:

  • The overhead in code to print a single message is massiv.
  • The output is no formated like maven output
  • I cannot attach a severity to the message (e.g. DEBUG, INFO, ERROR, etc)

Currently an Ant-echo looks like this (see line with "hello world"):

[INFO] --- maven-antrun-plugin:1.7:run (default) @ ejpd-alertmanager-ear ---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
main:
 [echo] hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

However, I expect it to look like this (see line with "hello world").

[INFO] --- maven-antrun-plugin:1.7:run (default) @ ejpd-alertmanager-ear ---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
[INFO] hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

I'm positive, I am missing something here, since I cannot be the first to raise this demand. Thank you for any smart hint.

Answer

khmarbaise picture khmarbaise · Apr 2, 2013

You should try the Maven Echo plugin:

<plugin>
  <groupId>com.soebes.maven.plugins</groupId>
  <artifactId>maven-echo-plugin</artifactId>
  <version>0.1</version>
  <executions>
    <execution>
      <phase>initialize</phase>
      <goals>
        <goal>echo</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <echos>
      <echo>This is the Text which will be printed out.</echo>
    </echos>
  </configuration>
</plugin>

Or furthermore take a deeper look into the integration test of the plugin.

which is available via Maven Central. BTW: If you have further requests/improvements just file in an issue.