如何在Maven中显示消息

问题描述 投票:53回答:4

如何在Maven中显示消息?

在ant中,我们确实有“echo”来显示消息,但是在maven中,我该怎么做?

java maven-2
4个回答
48
投票

你可以使用antrun插件:

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

但有一个问题是你必须选择the build lifecycle的哪个阶段来绑定它(我的例子是插件绑定到generate-resources)。与Ant不同,您不是自己控制生命周期,而只是将插件绑定到预定义生命周期中的某些点。根据您实际尝试的内容,这可能对您的用例有意义,也可能没有意义。


12
投票

你可以使用Groovy Maven Plugin

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

上面的配置将产生以下输出:

[INFO] Test message: Hello, World!

10
投票

你可以使用Björn Ekryd发表于Echo Maven PluginMaven 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] ------------------------------------------------------------------------

此外,这个插件有95% code coverage,非常酷。


4
投票
<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>
© www.soinside.com 2019 - 2024. All rights reserved.