spring-cloud / spring-cloud-contract

Support for Consumer Driven Contracts in Spring
https://cloud.spring.io/spring-cloud-contract
Apache License 2.0
719 stars 439 forks source link

Failed to build after Gradle 8.6 upgrade #2099

Closed rivancic closed 8 months ago

rivancic commented 9 months ago

Describe the bug

I'm using following versions

When upgrading from Gradle 8.5 to 8.6 I get following message when project goes through the configuration phase:

      > Failed to apply plugin class 'org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin'.
         > Could not create domain object 'contractTest' (JvmTestSuite)`

I think issue originates from this place SpringCloudContractVerifierGradlePlugin.java#L147

dependencies.getImplementation().add(dependencies.project());

Gradle 8.5 version of JvmComponentDependencies JvmComponentDependencies is annotated with @Incubating annotation means it can change anytime.

Gradle 8.6 changed org.gradle.api.artifacts.dsl.DependencyAdder to org.gradle.api.artifacts.dsl.DependencyCollector.

Now I got it its the same issue as -> https://github.com/spring-cloud/spring-cloud-contract/issues/2098

Code in the plugin didn't change much around contractTestSuite dependencies.

I assume to be compatible with Gradle 8.6 internal API you'll have to compile this plugin with Gradle 8.6 version. Or use plugin like mentioned here: https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281/2 https://github.com/gradle-plugins/toolbox To specify internal Gradle API version: https://github.com/spring-cloud/spring-cloud-contract/blob/main/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/build.gradle#L70

Current one is build with Gradle 8.3

4.0.3 is build with 7.6.1


Sample

I'll provide a sample application later.

Exception Stack Trace

Caused by: java.lang.NoSuchMethodError: 'org.gradle.api.artifacts.dsl.DependencyAdder org.gradle.api.plugins.jvm.JvmComponentDependencies.getImplementation()'
        at org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin.lambda$apply$0(SpringCloudContractVerifierGradlePlugin.java:147)
        at org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuite.dependencies(DefaultJvmTestSuite.java:297)
        at org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin.lambda$apply$11(SpringCloudContractVerifierGradlePlugin.java:138)

Whole stack trace:

gradle-stub-exception.txt

rivancic commented 9 months ago

Seems similar to this one, while I don't use test suites in the project, just unit5 platform. https://github.com/spring-cloud/spring-cloud-contract/issues/1863

Gradle 8.6 release doesn't mention much about test suites, so I'm wondering form where does the breaking change come. https://github.com/spring-cloud/spring-cloud-contract/issues/2099

OlgaMaciaszek commented 8 months ago

Closing as duplicate of gh-2098.