如何在没有Antrun插件的情况下在Maven中回显?

fed*_*der 11 logging maven maven-antrun-plugin

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

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

  • 打印单个消息的代码开销是massiv.
  • 输出没有形成像maven输出
  • 我无法在消息中附加严重性(例如DEBUG,INFO,ERROR等)

目前Ant-echo看起来像这样(参见"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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

但是,我希望它看起来像这样(见"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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我很肯定,我在这里遗漏了一些东西,因为我不能成为第一个提出这种需求的人.谢谢你的任何聪明提示.

khm*_*ise 5

你应该尝试Maven Echo插件:

<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>
Run Code Online (Sandbox Code Playgroud)

或者进一步深入了解插件集成测试.

可通过Maven Central获得.顺便说一句:如果您有进一步的请求/改进,只需提交问题.


Ben*_*son 5

您可以使用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>
Run Code Online (Sandbox Code Playgroud)
[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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

此外,这个插件有95% 的代码覆盖率,这很酷。


Dav*_*Rlz 1

我自己没有尝试过,但这里有一个插件可能会有所帮助:

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

  • 尝试 Maven Central 中提供的“echo-maven-plugin”:https://code.google.com/p/echo-maven-plugin/ (5认同)