Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to echo in Maven without Antrun plugin?

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.

like image 616
feder Avatar asked Apr 02 '13 12:04

feder


People also ask

How do you echo in POM xml?

We can use the "echo" Ant task to display a value of a property. The following fragment of a pom. xml file binds the antrun:goal to the validate build lifecycle phase. It uses the "echo" Ant task to display the value of the pom.

What is Maven AntRun plugin used for?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.

How do I run an Ant script from Maven?

Action. Configure the run goal form the Maven AntRun plugin. Define any properties you wish to pass to the external Ant build, and then call the external Ant build with the ant task, specifying the antfile and target you wish to execute. To execute this external Ant build, run mvn package.

Can we use Maven and Ant together?

As with any other Maven plugin, to make use of AntRun plugin, we need to define executions. Since we declared our plugin to run during Maven's package phase, running Maven's package goal will execute our plugin configuration above.


2 Answers

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.

like image 103
khmarbaise Avatar answered Oct 17 '22 05:10

khmarbaise


You can use Björn Ekryd's Echo Maven Plugin, which is published in Maven Central.

It has a normal amount of XML required for a Maven plugin, the output is formatted like the other Maven log lines, and you can assign a severity level to your message (default is INFO).

<plugin>
    <groupId>com.github.ekryd.echo-maven-plugin</groupId>
    <artifactId>echo-maven-plugin</artifactId>
    <version>1.2.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>echo</goal>
            </goals>
            <configuration>
                <message>war has changed</message>
                <level>INFO</level>
            </configuration>
        </execution>
    </executions>
</plugin>

[INFO] --- maven-war-plugin:2.4:war (default-war) @ mymodule ---
[INFO] Packaging webapp
[INFO] Processing war project
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (default) @ mymodule ---
[INFO] war has changed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Also, this plugin has 95% code coverage, which is pretty cool.

like image 28
Ben Hutchison Avatar answered Oct 17 '22 05:10

Ben Hutchison