2013-04-02 23 views
11

如何在执行mvn命令(阶段/目标)时打印到控制台,但不使用Maven Antrun插件?如何在没有Antrun插件的Maven中进行回显?

为什么我拒绝Antrun解决方案:

  • 代码的开销打印一条消息是马西沃。
  • 输出被无格式化等行家输出
  • 我不能严重性附加到消息(例如DEBUG,INFO,ERROR,等)

目前一个Ant回波看起来像这样(参见线与“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] ------------------------------------------------------------------------ 

但是,我希望它看起来像这样(请参阅“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] ------------------------------------------------------------------------ 

我很积极,我在这里错过了一些东西,因为我不能第一个提出这个需求。感谢您提供任何智能提示。

+0

你想要打印什么?输出将包含正在执行的阶段/目标的详细信息。 – DaveRlz

+0

Hi Dave,1st)执行目标时的属性值(我想检查运行时是否设置了正确的变量,例如operting system,运行maven-resources-plugin时的连接属性等)。 2)当执行antrun复制或移动任务(或者再次执行maven-resources-plugin)时,我想以maven-for-style形式回显。说,从[信息]开始。例如[INFO]成功将文件x复制到路径y。我有道理吗? – feder

回答

1

我还没有尝试过这个自己,但这里有一个插件,它可以帮助:

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

+0

不幸的是,这个插件不在Maven中心。 – khmarbaise

+0

谷歌快速检查显示它可以从这个链接的mvn仓库中获得:http://mvnrepository.com/artifact/com.soebes.maven.plugins/maven-echo-plugin - 好的,它不完全一样,我最初回答,但它看起来做同样的任务。 – DaveRlz

+0

也许这就是我们现在所能得到的。谢谢。 – feder

5

你应该尝试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> 

或者还需要更深入地了解integration test of the plugin.

这是通过Maven中心可用。顺便说一句:如果你有进一步的请求/改进只是文件in an issue

3

您可以使用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! 
1

可以使用Björn EkrydEcho Maven Plugin,其发表在Maven Central

它具有Maven插件所需的正常XML数量,输出格式与其他Maven日志行相似,并且可以为消息指定严重级别(默认为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] ------------------------------------------------------------------------ 

此外,该插件有95% code coverage,这是很酷。

相关问题