Search code examples
spring-bootgradlespring-cloud-contract

Generated test sources not getting invoked as part of the build


Having:

  • added Spring Cloud Contract plugin and configured it for baseClassMappings as well as basePackageForTests
  • added Spring Cloud Contract verifier
  • added required base classes for generated tests
  • and defined groovy contract

successfully generates test sources (which pass when run directly e.g. from within the IDE) under cdc/build/generated-test-sources/contracts/com/example/cdc/contract/verifier/tests/producer/practice

But...

These generated test sources do not get invoked as part of the build e.g. ./gradlew clean build meaning I do not know if I have broken the contract until I run generated tests manually e.g. from the IDE.

Have I missed a step?

Producer project: https://github.com/bilalwahla/cdc


Solution

  • You're using Kotlin. We have an issue for adding source sets in Gradle better (https://github.com/spring-cloud/spring-cloud-contract/issues/872). Until then just set

    sourceSets {
        test.java.srcDirs += new File(project.buildDir, "generated-test-source").toString()
    }
    

    With this issue being closed (https://github.com/spring-cloud/spring-cloud-contract/issues/888), you can check out that the latest snapshots should work better for you.