Search code examples
spring-bootspring-cloud-contract

Spring Cloud Contract remote artifact download clashes with local, how to make it temporary?


I am having an issue with Spring Cloud Contracts 2.0.0.M6, or there is something I must be misunderstanding about how to properly configure the stub runner tests.

I want to always download the artifact remotely, so I have set stubsMode to REMOTE.

When I run the test locally where I have the artifact in my .m2 directory, it fails. That's fine, and I can understand points made by one of the authors here.

The issue I have is that when I delete the local stub jars, and run the test case, the artifacts are downloaded and placed inside my .m2 directory again. Effectively this only allows me to run a stub runner once, then it fails because I have files locally. I have to keep deleting the artifact from .m2 after each test run.

I have worked around this by configuring:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <systemPropertyVariables>
            <maven.repo.local>
                ${project.build.directory}/repo/${maven.build.timestamp}
            </maven.repo.local>
        </systemPropertyVariables>
    </configuration>
</plugin>

Which means that for every time the stub runner runs, it will check and download to a new "random" directory /target/repo/<date>.

What is the proper way of doing this?


Solution

  • This problem might (it doesn't always happen) occur in CI systems when you have a shared .m2. In the next release (1.2.x and 2.0.0), thanks to closing of this issue https://github.com/spring-cloud/spring-cloud-contract/issues/545 , you'll be able to pass stubrunner.snapshot-check-skip system property or STUBRUNNER_SNAPSHOT_CHECK_SKIP environment variable or set the plugin property (for 2.0.0 only) to disable the check.