一直有在項目中使用Maven來編譯,測試,發布Java代碼。 最近一直有在學習Groovy。
也有考慮使用Gradle來重寫build 腳本,但后來發現了GMaven, 是一個不想大動干戈的情況下不錯的選擇。
我已經說服Team的成員使用GMaven了,相應地我也已經把測試測框架做了小小的微調。
Step by Step(修改pom.xml):
1. 引入Groovy庫
<dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.8.1</version> <scope>provided</scope> </dependency>
2.導入GMaven plugin
<plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <executions> <execution> <goals> <!-- <goal>generateStubs</goal> <goal>compile</goal> --> <goal>generateTestStubs</goal> <goal>testCompile</goal> </goals> <configuration> <debug>true</debug> <verbose>true</verbose> <stacktrace>true</stacktrace> <defaultScriptExtension>.groovy</defaultScriptExtension> <providerSelection>1.7</providerSelection> <source> <fileset> <directory>${pom.dir}</directory> <includes> <include>**/script/*.groovy</include> </includes> </fileset> </source> </configuration> </execution> </executions> </plugin>
3.spock -- Groovy實現的BDD測試框架
<dependency> <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>0.6-groovy-1.8</version> <scope>test</scope> </dependency> <plugin> <groupId>org.spockframework</groupId> <artifactId>spock-maven</artifactId> <version>0.6-groovy-1.8</version> <executions> <execution> <goals> <goal>find-specs</goal> </goals> </execution> </executions> </plugin>