# Spring Cloud Contract Maven Plugin –

## Spring Cloud Contract Maven Plugin

## 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>
                                            <contractsRepositoryUrl>http://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.

            <properties>
                    <!-- We don't want the tests to be executed cause we're just build stubs -->
                    <skipTests>true</skipTests>
                    <!-- The target / build folder needs to be excluded - we don't want to check its contents -->
                    <excludeBuildFolders>true</excludeBuildFolders>
            </properties>

            <build>
                    <plugins>
                            <plugin>
                                    <groupId>org.springframework.cloud</groupId>
                                    <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                                    <configuration>
                                            <!-- By default it would search under src/test/resources/ -->
                                            <contractsDirectory>${project.basedir}</contractsDirectory>
                                    </configuration>
                            </plugin>
                    </plugins>
            </build>