在maven中没有如Ant中的echo命令,只有借助于外部插件来打印消息,这些插件用起来都很繁琐,如果maven能提供一个这样的命令,无疑是极好的。
下面列出几种可利用的打印消息的方法,都采用了maven插件的方式进行处理,各方式特点总结:
1、方式1,3,4均支持输出多条消息,方式2未能找到输出多条消息的配置。
2、方式2,3支持输出消息日志级别(info、warn、error等),方式1,4不支持。
方式1,利用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>
<echo>Wahaha!</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
方式2,利用ekryd的echo插件:
<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>Echo test: ${env.JAVA_HOME}</message>
<level>INFO</level>
</configuration>
</execution>
</executions>
</plugin>
方式3,利用groovy的echo插件:
<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!');
log.info('Wahaha!');
</source>
</configuration>
</execution>
</executions>
</plugin>
方式4,利用soebes的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>
<echo>Hello World.</echo>
</echos>
</configuration>
</plugin>
参考:
1、http://stackoverflow.com/questions/15763915/how-to-echo-in-maven-without-antrun-plugin
2、http://stackoverflow.com/questions/3416573/how-can-i-display-a-message-in-maven