How can I display a message in Maven

前端 未结 4 1737
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 12:17

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?

相关标签:
4条回答
  • 2021-02-01 12:32

    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!
    
    0 讨论(0)
  • 2021-02-01 12:45

    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.

    0 讨论(0)
  • 2021-02-01 12:46

    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.

    0 讨论(0)
  • 2021-02-01 12:55
    <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>
    
    0 讨论(0)
提交回复
热议问题