How to echo in Maven without Antrun plugin?
Asked Answered
F

4

13

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.

Fiorin answered 2/4, 2013 at 12:17 Comment(2)
What exactly do you want to print out? The output will already contain details of the phase/goal that is being executed.Teleprinter
Hi Dave, 1st) property values when a goal has been executed (I want to check if a variable is set correctly at runtime. e.g. operting system, concatenated properties when running the maven-resources-plugin. etc.). 2) When executing antrun copy or move task (or again the maven-resources-plugin), I want to echo in a maven-formated-style. Saying, starting with [INFO]. e.g. [INFO] Successfully copied file x to path y. Do I make sense?Fiorin
T
1

I haven't tried this myself but there is a plugin here which may help:

http://code.google.com/p/maven-echo-plugin/

Teleprinter answered 2/4, 2013 at 12:52 Comment(5)
Unfortunately this plugin is not in Maven Central.Ollie
A quick check on google shows it is available from mvn repository at this link: mvnrepository.com/artifact/com.soebes.maven.plugins/… - ok, it's not exactly the same as I originally answered but it looks to do the same task.Teleprinter
Probably that is all we can get for now. Thanks.Fiorin
I have written that the plugin from code.google.com is not available in Maven central where the given plugin (groupId: com.soebes.maven.plugins) is available from maven central.Ollie
Try the 'echo-maven-plugin' available in Maven Central: code.google.com/p/echo-maven-pluginDouceur
O
5

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.

Ollie answered 2/4, 2013 at 13:10 Comment(0)
P
5

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.

Previdi answered 3/3, 2016 at 5:10 Comment(1)
Cool, especially that I can use <fromFile> to output the content of a file. Just perfect for my needs! This should be the accepted answer as of today.Dortheydorthy
R
3

You can use Groovy Maven Plugin for this.

<plugin>                                                         
    <groupId>org.codehaus.gmaven</groupId>                       
    <artifactId>groovy-maven-plugin</artifactId>                 
    <version>2.0</version>                                       
    <executions>                                                 
        <execution>                                              
            <phase>validate</phase>                              
            <goals>                                              
                <goal>execute</goal>                             
            </goals>                                             
            <configuration>                                      
                <source>                                         
                    log.info('Test message: {}', 'Hello, World!')
                </source>                                        
            </configuration>                                     
        </execution>                                             
    </executions>                                                
</plugin>                                                        

The configuration above will produce the following output:

[INFO] Test message: Hello, World!
Rozamond answered 18/11, 2014 at 11:48 Comment(0)
T
1

I haven't tried this myself but there is a plugin here which may help:

http://code.google.com/p/maven-echo-plugin/

Teleprinter answered 2/4, 2013 at 12:52 Comment(5)
Unfortunately this plugin is not in Maven Central.Ollie
A quick check on google shows it is available from mvn repository at this link: mvnrepository.com/artifact/com.soebes.maven.plugins/… - ok, it's not exactly the same as I originally answered but it looks to do the same task.Teleprinter
Probably that is all we can get for now. Thanks.Fiorin
I have written that the plugin from code.google.com is not available in Maven central where the given plugin (groupId: com.soebes.maven.plugins) is available from maven central.Ollie
Try the 'echo-maven-plugin' available in Maven Central: code.google.com/p/echo-maven-pluginDouceur

© 2022 - 2024 — McMap. All rights reserved.