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

Gradle plugin fail on gradle version 8.6 #2098

Closed welovelain closed 8 months ago

welovelain commented 9 months ago

Describe the bug After updating to gradle 8.6, I can't build the project anymore. Stacktrace:

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)
        at org.gradle.api.internal.DefaultMutationGuard$1.execute(DefaultMutationGuard.java:45)
        at org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:122)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1.run(DefaultCollectionCallbackActionDecorator.java:110)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.execute(DefaultCollectionCallbackActionDecorator.java:107)
        at org.gradle.internal.ImmutableActionSet$SetWithFewActions.execute(ImmutableActionSet.java:285)
        at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:262)
        at org.gradle.api.internal.DefaultNamedDomainObjectCollection.doAdd(DefaultNamedDomainObjectCollection.java:124)
        at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:256)
        at org.gradle.api.internal.DefaultNamedDomainObjectCollection$AbstractDomainObjectCreatingProvider.tryCreate(DefaultNamedDomainObjectCollection.java:1005)
        ... 199 more

build.gradle

plugins {
  id 'org.springframework.boot'
  id 'java'
  id 'idea'
  id 'spring-cloud-contract'
  id "io.freefair.lombok"
}
marcingrzejszczak commented 9 months ago

@shanman190 please help :pray:

shanman190 commented 9 months ago

@marcingrzejszczak, yeah I'll take a look. Just initial review of the Gradle proper jvm-test-suite plugin shows that the API surface that we use is the same, but they renamed the return type from DependencyAdder to DependencyCollector. However, we don't use the type directly, but rather indirectly, so we shouldn't have been broken here.

To summarize, I'm not sure why it's saying the method isn't found and we should be compatible with Gradle 8.6 without any changes. I'll try to debug it here soon and see what's going on.

shanman190 commented 9 months ago

@welovelain, what version of the Spring Cloud Contract Gradle Plugin are you using?

jmuenchenberg commented 9 months ago

we encountered pretty much the same problem using spring-cloud-contract-gradle-plugin:4.1.1

welovelain commented 9 months ago

Yes, 4.1.1 for us too.

rivancic commented 9 months ago

I have same issue with version 4.0.3.

shanman190 commented 9 months ago

So I've reviewed this and it is a binary breaking change at the JVM level. The code compiles correctly on 8.5 and 8.6. but using a plugin version built with 8.6 on a lower Gradle version results in the same issue as well.

shanman190 commented 9 months ago

The Gradle team upstream has chosen to leave the API as is, so I'll submit a PR to use reflection to handle the 7.6-8.5 version ranges.