如何在执行mvn命令(在阶段/目标中)但不使用Maven Antrun插件时打印到控制台?
为什么我拒绝Antrun解决方案:
目前,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] ------------------------------------------------------------------------
但是,我希望它看起来像这样(见“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 :(得分: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 Central获得。顺便说一句:如果你有进一步的请求/改进,只需提交in an issue。
答案 1 :(得分: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!
答案 2 :(得分:2)
您可以使用Björn Ekryd发布的Echo 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,非常酷。
答案 3 :(得分:1)
我自己没试过,但这里有一个插件可能会有所帮助: