1
votes

I am trying to create an example POC for my team to use Spring cloud contract.

I was able to receive Green-Pass for Producer side but on Consumer side, I keep getting
No stubs or contracts were found for [com.datson:cloudcontract-producer:+:stubs] and the switch to fail on no stubs was set. The contracts are present.

I tried several user-case as described in the offical spring cloud document.

@AutoConfigureStubRunner(ids = "com.datson:cloudcontract-producer:+:8080", stubsMode = StubRunnerProperties.StubsMode.LOCAL)

@AutoConfigureStubRunner(ids = "com.datson:cloudcontract-producer:+:stubs"

https://cloud.spring.io/spring-cloud-contract/reference/html/getting-started.html#getting-started-cdc-consumer-run

here is the consumer code sample: https://github.com/Yayan89/springboot-config-server/tree/master/cloudcontract-consumer
here is the producer code sample: https://github.com/Yayan89/springboot-config-server/tree/master/cloudcontract-producer

Might be something silly that I missed out.

2

2 Answers

2
votes

In the presented samples you need to install a jar in your local m2 to fetch it from the consumer side (please read the documentation on how to fetch the contracts directly from the drive). If you check this sample and the gradle build https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/scripts/runGradleBuilds.sh#L37 you will see that you should run sth like this

./gradlew build publishToMavenLocal

assuming that you have maven-publish plugin or

./gradlew build install

assuming that you have a maven plugin

1
votes

Thanks for reply @MarcinGrejszzak, just one thing I want to make sure if I understand correctly. Producer needs to publish mavenlocal (.m2) for consumer to be able to build it. Is my statement correct?

id 'maven-publish' and we need to add our producer in gradle/mvn build

implementation("com.datson:cloudcontract-producer:+:stubs") {
        transitive = false
    }

my code works now with

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureStubRunner(
    stubsMode = StubRunnerProperties.StubsMode.LOCAL,
    ids = "com.datson:cloudcontract-producer:+:stubs:0.0.1:8090"
)
@AutoConfigureMockMvc
public class LoanApplicationServiceTest {

@Autowired
MockMvc mockMvc;

@Test
public void given_WhenPassEvenNumberInQueryParam_ThenReturnEven() throws Exception {

    mockMvc.perform(MockMvcRequestBuilders.put("/fraudcheck")
        .contentType(MediaType.APPLICATION_JSON))
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andExpect(MockMvcResultMatchers.content().string("Even"));
}}