Adding support for Spock testing to your Java maven project is quite an easy job. All you have to do is the following:
Add the gmaven plugin
<plugin>
<groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.4</version> <configuration> <providerSelection>2.0</providerSelection> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>testCompile</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.codehaus.gmaven.runtime</groupId> <artifactId>gmaven-runtime-2.0</artifactId> <version>1.4</version> <exclusions> <exclusion> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.2.2</version> </dependency> </dependencies> </plugin `
- Configure the maven surefire plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.8.1</version> <configuration> <includes> <include>**/*Test.class</include> <include>**/*Spec.class</include> </includes> </configuration> <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-junit4</artifactId> <version>2.8.1</version> </dependency> </dependencies> </plugin>
- Add some maven dependencies
`<dependency> <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>0.7-groovy-2.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.2.2</version> <scope>test</scope> </dependency>
IntelliJ Java Project: Spoc configuration
- Add the scr/test/groovy folder under your project structure.