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?
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:
When using gradle generateClientStubs
don't forget the leading slash in the absolute URI to your stubs directory. e.g. stubs://file:///User/me/my-contracts-project/build/stubs
.
The stub runner starts a server on port 8080, so you must run your stubs on a different port. You can override the port the stub runner starts on with the usual -Dserver.port
.