Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PACT samples don't work for gradle builds #178

Open
OlgaMaciaszek opened this issue Nov 25, 2020 · 6 comments
Open

PACT samples don't work for gradle builds #178

OlgaMaciaszek opened this issue Nov 25, 2020 · 6 comments
Assignees
Labels

Comments

@OlgaMaciaszek
Copy link
Collaborator

No description provided.

@gavvvr
Copy link

gavvvr commented Feb 21, 2022

Was about to post this bug, but it's already registered.

I will add more info on this.

I was able to publish pact contracts from consumer_pact project successfully.
But I am having troubles while generating producer tests with ./gradlew generateContractTests for producer_pact.
The error I get is:

> Task :copyContracts FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':copyContracts'.
> Remote repositories for stubs are not specified and work offline flag wasn't passed

Sounds weird, because It's obvious that pact broker url is specified:

contractRepository {
repositoryUrl = "pact://http://localhost:8085"
}

Based on what I can see in debugger the problem is that SpringFactoriesLoader fails to discover StubDownloaderBuilder implementations (in particular PactStubDownloaderBuilder).

I guess the classpath of Gradle's copyContracts task execution simply does not contain the org.springframework.cloud:spring-cloud-contract-pact. I tried to play with the Gradle's configuration for this dependency (tried contractTestImplementation, implementation and api), but no luck. I would have expected contractTestImplementation to work tbh.


UPD: Found a workaround. Placing the following on the top of build script fixes the problem:

buildscript {
    dependencies {
        classpath("org.springframework.cloud:spring-cloud-contract-pact:3.1.1")
    }
}

If you have a multi-module Gradle project, this should be placed into the root build.gradle, otherwise it won't work.

@marcingrzejszczak
Copy link
Contributor

@shanman190 do you think we have a problem with the gradle plugin?

@shanman190
Copy link
Contributor

@marcingrzejszczak, yeah this is a bug in the plugin. At the moment, we have the dependencies to enable use of local and git-based remote contracts. The Gradle plugin is presently doing the downloading from within the Gradle process itself which explains why when @gavvvr adds the pact dependency to Gradle's buildscript it then gains the capability to download pact broker based contracts. I do think we could shove the download work itself into a worker (assuming that Kotlin doesn't creep back into the classpath again) and take advantage of the contractTestInplementation classpath so that end users don't have to double specify the dependency though.

I would have expected though that the dependency should be workable on the buildscript classpath anywhere the Spring Cloud Contract plugin is applied (ie. If it's on a root project, then the dependency needs to appear there; if it's only on a subproject, then the dependency could appear there per project as needed).

@marcingrzejszczak
Copy link
Contributor

Great, will you look into that in your spare time @shanman190 ?

@shanman190
Copy link
Contributor

Absolutely, @marcingrzejszczak. I'll see about submitting a PR with the fix over the next few days.

@marcingrzejszczak
Copy link
Contributor

Thanks, I really appreciate it @shanman190 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants