8. Migrations
Prev |  |

# 8. Migrations

In the following document we will write about necessary migration steps between versions.

## 8.1 1.0.x → 1.1.x

### 8.1.1 New structure of generated stubs

In `1.1.x` we have introduced a changed structure of generated stubs. So if you’ve been using the following `@AutoConfigureWireMock` notation to use the stubs from classpath

    @AutoConfigureWireMock(stubs = "classpath:/customer-stubs/mappings", port = 8084)

It will no longer work with the new stubs. You have to either change the location of stubs to : `classpath:…​/META-INF/groupId/artifactId/version/mappings` as follows

    @AutoConfigureWireMock(stubs = "classpath:customer-stubs/META-INF/travel.components/customer-contract/1.0.2-SNAPSHOT/mappings/", port = 8084)

Or migrate to the new classpath based `@AutoConfigureStubRunner`.

If however you don’t want to do that and you want to remain with the old structure just set your plugin tasks accordingly. Example for the structure presented in the snippet above.

Maven.

    <!-- start of pom.xml -->

    <properties>
        <!-- we don't want the verifier to do a jar for us -->
        <spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip>
    </properties>

    <!-- ... -->

    <!-- You need to set up the assembly plugin -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>stub</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <attach>true</attach>
                            <descriptor>${basedir}/src/assembly/stub.xml</descriptor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <!-- end of pom.xml -->

    <!-- start of stub.xml-->

    <assembly
    	xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 https://maven.apache.org/xsd/assembly-1.1.3.xsd">
    	<id>stubs</id>
    	<formats>
    		<format>jar</format>
    	</formats>
    	<includeBaseDirectory>false</includeBaseDirectory>
    	<fileSets>
    		<fileSet>
    			<directory>${project.build.directory}/snippets/stubs</directory>
    			<outputDirectory>customer-stubs/mappings</outputDirectory>
    			<includes>
    				<include>**/*</include>
    			</includes>
    		</fileSet>
    		<fileSet>
    			<directory>${basedir}/src/test/resources/contracts</directory>
    			<outputDirectory>customer-stubs/contracts</outputDirectory>
    			<includes>
    				<include>**/*.groovy</include>
    			</includes>
    		</fileSet>
    	</fileSets>
    </assembly>

    <!-- end of stub.xml-->

Gradle.

    task copyStubs(type: Copy, dependsOn: 'generateWireMockClientStubs') {
    //    Preserve directory structure from 1.0.X of spring-cloud-contract
        from "${project.buildDir}/resources/main/customer-stubs/META-INF/${project.group}/${project.name}/${project.version}"
        into "${project.buildDir}/resources/main/customer-stubs"
    }

## 8.2 1.1.x → 1.2.x

### 8.2.1 Custom `HttpServerStub`

By introducing a method `String registeredMappings()` in the public interface `HttpServerStub`, if you wrote a custom `HttpServerStub` implementation, you’ll have to implement that method too. It should return a `String` representing all mappings available in a single `HttpServerStub`. Related to issue 355.

### 8.2.2 New packages for generated tests

The flow for setting the generated tests package name will look like this:

- pick `basePackageForTests`
- if `basePackageForTests` wasn’t set pick the package from `baseClassForTests`
- if `baseClassForTests` wasn’t set pick `packageWithBaseClasses`
- if nothing got set pick the default `org.springframework.cloud.contract.verifier.tests` value

Related to issue 260.

Prev |  |
7. Generating Contracts using RestDocs | Home |