Spring Cloud Contract Test + Gradle + Kotlin DSL : Contracts are not found

158 views Asked by At

Error facing while running ./gradlew build

* What went wrong:
Execution failed for task ':copyContracts'.
> Contracts could not be found: []
  Please make sure that the contracts were defined, or set the [failOnNoContracts] flag to [false]

  • spring boot version: 3.1.3
  • spring cloud version : 2022.0.4
  • gradle spring cloud plugin version : 4.0.4
  • kotlin version: 1.9.0

project structure looks like

mainProject
 -childProject
    -src
       -main
       -test
       -contractTest
    -build.gradle.kts
 -secondChildProject
 -parent build.gradle.kts

build.gradle.kts looks as below


plugins {
    id("org.springframework.cloud.contract")
}


dependencies{
    testImplementation("org.springframework.cloud:spring-cloud-contract-spec-kotlin")
    testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier")
    testImplementation("org.springframework.cloud:spring-cloud-starter-contract-stub-runner")

}

dependencyManagement {
    imports {
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}


contracts {
    contractsDslDir = file("/src/contractTest/resources/contracts")
    packageWithBaseClasses.set("com.abc.contract")
    baseClassMappings.baseClassMapping(
        ".*",
        "com.abc.contract.ContractBaseClass",
    )
}

Stacktrace error shows as if its not reading my properties defined in build.gradle.kts and not reading contracts location.

Caused by: org.gradle.api.GradleException: Contracts could not be found: []
Please make sure that the contracts were defined, or set the [failOnNoContracts] flag to [false]
        at org.springframework.cloud.contract.verifier.plugin.ContractsCopyTask.throwExceptionWhenFailOnNoContracts(ContractsCopyTask.java:275)
        at org.springframework.cloud.contract.verifier.plugin.ContractsCopyTask.sync(ContractsCopyTask.java:186)

Also, tried adding failOnNoContracts = false or failOnNoContracts(false) in the build.gradle.kts, however the same error.

0

There are 0 answers