[英]How can I display a message in Maven
如何在Maven中显示消息?
在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>
但有一个问题是你必须选择构建生命周期的哪个阶段来绑定它(我的示例将插件绑定到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>
上面的配置将产生以下输出:
[INFO] Test message: Hello, World!
您可以使用BjörnEkryd的Echo Maven插件 ,该插件在Maven Central发布:
<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%的代码覆盖率 ,这是非常酷的。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.