spring-cloud-contract

How to run local contracts with Spring Cloud Contract stub runner


I have defined some Spring Cloud Contracts that I have packaged into a jar using gradle verifierStubsJar. I would like to run the stubs in that jar with the Spring Cloud Contract stub runner jar. I do not want to have to publish the stubs jar to an artifact repository like Artifactory or a local Maven repository. I just want to run the stubs. How do I pass the location of the jar containing my stubs to the stub runner jar?


Solution

  • If you use gradle generateClientStubs:

    curl -Lo stub-runner.jar https://search.maven.org/remotecontent?filepath=org/springframework/cloud/spring-cloud-contract-stub-runner-boot/2.2.1.RELEASE/spring-cloud-contract-stub-runner-boot-2.2.1.RELEASE.jar
    
    java -Djava.security-egd=/dev/./urandom -Dstubrunner.repositoryRoot=stubs://file://absolute/path/to/build/stubs -Dstubrunner.ids=com.company-contract:stubs:8081 -Dstubrunner.stubs-mode=REMOTE -jar stub-runner.jar
    

    If you use gradle verifierStubsJar:

    curl -Lo stub-runner.jar https://search.maven.org/remotecontent?filepath=org/springframework/cloud/spring-cloud-contract-stub-runner-boot/2.2.1.RELEASE/spring-cloud-contract-stub-runner-boot-2.2.1.RELEASE.jar
    
    java -cp stub-runner.jar:build/libs/my-contract-stubs.jar -Djava.security-egd=/dev/./urandom -Dstubrunner.ids=com.company:my-contract:stubs:8081 -Dstubrunner.stubs-mode=CLASSPATH org.springframework.boot.loader.JarLauncher
    

    Gotchas: