How to echo in Maven without Antrun plugin?

后端 未结 4 705
攒了一身酷
攒了一身酷 2021-02-13 16:22

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 over
相关标签:
4条回答
  • 2021-02-13 16:52

    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.

    0 讨论(0)
  • 2021-02-13 16:54

    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-13 17:01

    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.

    0 讨论(0)
  • 2021-02-13 17:09

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

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

    0 讨论(0)
提交回复
热议问题