Java 如何在Maven中显示消息
如何在Maven中显示消息Java 如何在Maven中显示消息,java,maven-2,Java,Maven 2,如何在Maven中显示消息 在ant中,我们确实有“echo”来显示消息,但在maven中,我如何才能做到这一点?您可以使用antrun插件: <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-resources</phase
在ant中,我们确实有“echo”来显示消息,但在maven中,我如何才能做到这一点?您可以使用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>
将其绑定到(我的示例将插件绑定到generateresources
)。与Ant不同,您不是自己控制生命周期,而是将插件绑定到预定义生命周期中的某些点。这取决于您实际要做的事情,对于您的用例来说可能有意义,也可能没有意义。
<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>
maven antrun插件
产生资源
跑
[您的邮件]:${Urkey}
您可以使用它
<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>
您可以使用的,发布在:
此外,这个插件还有一个功能,非常酷。为什么需要这样做?您的用例是什么?@PascalThivent说,如果我想跟踪某个属性的值-如何在不打印它的情况下做到这一点?请参阅下面的链接了解正确的sytax:maven antrun插件无法在windows中打印maven 3.3.3中的消息。Groovy插件工作得很好。你知道在构建失败时如何打印消息吗?我只想在构建结束时打印一条自定义消息。@LenglBoy我无法立即回答您的问题,但值得单独提问,而不是发表评论。它更多的是关于如何检测构建失败,而不是打印消息。您是如何执行的?我运行了mvn package
,但您可以将其绑定到任何您喜欢的文件。很酷,特别是我可以使用
输出文件内容。非常适合我的需要!这应该是公认的答案(我希望尽可能避免使用maven antrun插件)。
[INFO] Test message: Hello, World!
<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>