How can I display a message in Maven

JavaMaven 2

Java Problem Overview


How can I display a message in Maven?

In ant, we do have "echo" to display a message, but in maven, how can I do that?

Java Solutions


Solution 1 - Java

You can use the antrun plugin:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>Hello world!</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

One issue though is that you have to choose what phase of the build lifecycle to bind this to (my example has the plugin bound to generate-resources). Unlike Ant, you aren't controlling the lifecycle yourself, but rather just binding plugins to certain points in a pre-defined lifecycle. Depending on what you are actually trying to do, this may or may not make sense for your use case.

Solution 2 - Java

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

<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>
            </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.

Solution 3 - Java

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!

Solution 4 - Java

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>[your message]:${Urkey}</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavidView Question on Stackoverflow
Solution 1 - Javamatt bView Answer on Stackoverflow
Solution 2 - JavaBen HutchisonView Answer on Stackoverflow
Solution 3 - Javaᄂ ᄀView Answer on Stackoverflow
Solution 4 - JavaVenkatesh DayawarView Answer on Stackoverflow