I am trying to build the producer side of the spring-cloud-contract architecture . I have added the plugins required,and added the contract in the contracts directory which is being correctly picked up by the plugin in the build the contracts are correctly copied by the gradle build process into the stubs directory into contracts dir. The console stack before the Exception is as follows

> Task :[ProjectName]:generateClientStubs FAILED
Build cache key for task ':[ProjectName]:generateClientStubs' is 3cc52dc492987e9244ab97e5274ad851
Task ':[ProjectName]:generateClientStubs' is not up-to-date because:
  Task has failed previously.
Stubs output dir [/home/username/Projects/[ProjectName]/build/stubs/META-INF/[ProjectName]/[ProjectName]/2.4.9/mappings]
Spring Cloud Contract Verifier Plugin: Invoking DSL to client stubs conversion
Contracts dir is [/home/username/Projects/[ProjectName]/[ProjectName]/build/stubs/META-INF/[ProjectName]/[ProjectName]/2.4.9/contracts] output stubs dir is [/home/username/Projects/[ProjectName]/[ProjectName]/build/stubs/META-INF/[ProjectName]/[ProjectName]/2.4.9/mappings]
:[ProjectName]:generateClientStubs (Thread[Execution worker for ':' Thread 6,5,main]) completed. Took 0.003 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':common-services-service:generateClientStubs'.
> org.gradle.process.JavaExecSpec.getMainClass()Lorg/gradle/api/provider/Property;

gradle.build

plugins{
  id 'org.springframework.cloud.contract' version '3.1.6'
 }

dependencyManagement {
 imports {
    mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.5"
 }
 }

ext {
set('springCloudVersion', "2021.0.6")
 }


dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'

  }

tasks.named('contractTest') {
useJUnitPlatform()
 } 

tasks.named('test') {
useJUnitPlatform()
}


// tasks.create(type: Jar, name: 'verifierStubsJartest', dependsOn: 'generateClientStubs') {
//     baseName = project.name
//     classifier = contracts.stubsSuffix
//     from contractVerifier.stubsOutputDir
// }

contracts {
testMode = 'Explicit'
// contractsDslDir = file("/src/contractTest/resources/contracts")
// testFramework = "JUNIT5"
 // packageWithBaseClasses = 'com.example.SCCProducer'
   baseClassForTests='com.subex.ngp.sccBaseContractClass';
 generatedTestSourcesDir = project.file('src/generatedContract')

 // baseClassMappings {
 //     baseClassMapping(".*intoxication.*", "com.example.intoxication.contractBaseClass")
  //    }
 }

TestingContact.groovy:

package contracts

import org.springframework.cloud.contract.spec.Contract


Contract.make {
 request {
     method 'GET'
   url [url is correct and working ]

 }

response {
    status OK()
}
}

can anyone who has good knowledge on spring cloud contract please help me out in this. for anyFurther info about the exception or stacktrace please write down

I tried changing the dir of the contracts from default and giving the path of the dir also yet got same exception

1

There are 1 best solutions below

1
Gurushanth Gowdar On

Hello guys , I found the answer for the exception it is that the spring-cloud-contract 3.x is not compatible with the gradle version so i down graded the spring-cloud-contract version to 2.x it worked