maven 列印訊息或輸出訊息或列印日誌
阿新 • • 發佈:2019-01-02
在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