Fork me on GitHub

Configuration snippets

Here you’ll be able to see different Spring Cloud Contract Maven plugin configuration

Base class from mappings

Define regular expression mappings to map a contract to its base class.

                        <plugin>
                                <groupId>org.springframework.cloud</groupId>
                                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                                <configuration>
                                        <baseClassForTests>com.example.FooBase</baseClassForTests>
                                        <baseClassMappings>
                                                <baseClassMapping>
                                                        <contractPackageRegex>.*com.*</contractPackageRegex>
                                                        <baseClassFQN>com.example.TestBase</baseClassFQN>
                                                </baseClassMapping>
                                        </baseClassMappings>
                                </configuration>
                        </plugin>

Convention based mappings

Define a package in which base classes are placed. In this case we define a package called hello. If there’s a contract under /contracts/hello/V1/Contract.groovy` then we’ll search for a HelloV1Base base class. We’re taking two last folders from the path and combine them into a class name.

                        <plugin>
                                <groupId>org.springframework.cloud</groupId>
                                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                                <configuration>
                                        <packageWithBaseClasses>hello</packageWithBaseClasses>
                                </configuration>
                        </plugin>

Remote contracts

Here you can see a setup where we point to a repository where the JAR with the contracts got deployed.

                        <plugin>
                                <groupId>org.springframework.cloud</groupId>
                                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                                <configuration>
                                        <contractsMode>REMOTE</contractsMode>
                                        <contractsRepositoryUrl>
                                                https://link/to/your/nexus/or/artifactory/or/sth
                                        </contractsRepositoryUrl>
                                        <contractDependency>
                                                <groupId>com.example.standalone</groupId>
                                                <artifactId>contracts</artifactId>
                                        </contractDependency>
                                </configuration>
                        </plugin>

Setting up repo with common contracts

A setup of a repo that contains all common contracts. It can exclude the target / build folder that gets created when you’re installing stubs locally as a consumer.