Fork me on GitHub

Groovy Project with Spock Specifications

Sample minimal configuration for Groovy Project with Spock Specification

Test dependencies for generated contract verification tests

                <dependency>
                        <groupId>org.spockframework</groupId>
                        <artifactId>spock-core</artifactId>
                        <version>1.0-groovy-2.4</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.springframework.cloud</groupId>
                        <artifactId>spring-cloud-starter-contract-verifier</artifactId>
                        <version>${it-plugin.version}</version>
                        <scope>test</scope>
                </dependency>

Project configuration for Spring Cloud Contract Verifier, Groovy, Spock specifications and stub publishing

                        <plugin>
                                <groupId>org.springframework.cloud</groupId>
                                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                                <version>${spring-cloud-verifier-plugin.version}</version>
                                <extensions>true</extensions>
                                <configuration>
                                        <baseClassForTests>hello.BaseAccurest</baseClassForTests>
                                        <testFramework>SPOCK</testFramework>
                                </configuration>
                        </plugin>

                        <plugin>
                                <groupId>org.codehaus.gmavenplus</groupId>
                                <artifactId>gmavenplus-plugin</artifactId>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>compileTests</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
                                        <testSources>
                                                <testSource>
                                                        <directory>${project.basedir}/src/test/groovy</directory>
                                                        <includes>
                                                                <include>**/*.groovy</include>
                                                        </includes>
                                                </testSource>
                                                <testSource>
                                                        <directory>
                                                                ${project.build.directory}/generated-test-sources/contracts
                                                        </directory>
                                                        <includes>
                                                                <include>**/*.groovy</include>
                                                        </includes>
                                                </testSource>
                                        </testSources>
                                </configuration>
                        </plugin>
                        <plugin>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <configuration>
                                        <includes>
                                                <include>**/*Spec.java</include>
                                        </includes>
                                </configuration>
                        </plugin>

Base Specification class

/*
 * Copyright 2013-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hello

import io.restassured.module.mockmvc.RestAssuredMockMvc
import spock.lang.Specification

class BaseAccurest extends Specification {

        def setup() {
                RestAssuredMockMvc.standaloneSetup(new GreetingController())
        }

}