如何在Maven中显示消息
我如何在Maven中显示消息? 在ant,我们确实有“回声”显示一个消息,但在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>
一个问题是,你必须select什么阶段的生命周期来绑定这个(我的例子有插件绑定到generate-resources
)。 与Ant不同,您并不是自己控制生命周期,而只是将插件绑定到预定义生命周期中的特定点。 根据你实际正在做的事情,这可能会或可能不会对你的用例有意义。
你可以使用Groovy Maven插件来实现这一点。
<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>
上面的configuration将产生以下输出:
[INFO] Test message: Hello, World!
<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 Central发布的BjörnEkryd的Echo Maven插件 :
<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%的代码覆盖率 ,这非常酷。