Pact-jvm: Inconsistency found in documentation regarding startProviderTask and terminateProviderTask

Created on 11 Mar 2020  路  11Comments  路  Source: pact-foundation/pact-jvm

Both startProviderTask and terminateProviderTask expect closures as a property, but this is not stated in the documentation, and the example did not reflect the fact above.

Gradle 6.2.1
au.com.dius.pact:4.0.0

All 11 comments

startProviderTask and terminateProviderTask should be Gradle tasks. There is no other requirement on them.

startProviderTask and terminateProviderTask should be Gradle tasks. There is no other requirement on them.

While the README.MD states:

            startProviderTask = startTheApp
            terminateProviderTask = killTheApp

Actually it requires that the startTheApp and killTheApp are enclosed in {}, like

            startProviderTask = { startTheApp }
            terminateProviderTask = { killTheApp }

I've tested this with my test project, and it works without the braces. See https://github.com/uglyog/pact-gradle-test/blob/master/build.gradle#L66

Here is the output:

$ ./gradlew pactVerify

> Task :startTheApp
startTheApp

> Task :pactVerify_Activity_Service FAILED

Verifying a pact between Foo Web Client and Activity Service for tag tag/with/slash
  [from Pact Broker https://test.pact.dius.com.au/pacts/provider/Activity Service/consumer/Foo Web Client/version/1.0.2 (Tag tag/with/slash)]
  a request expecting null fields
      Request Failed - Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')

Verifying a pact between Foo Web Client 2 and Activity Service for tag tag/with/slash
  [from Pact Broker https://test.pact.dius.com.au/pacts/provider/Activity Service/consumer/Foo Web Client 2/version/1.0.2 (Tag tag/with/slash)]
  Given many activities exist
         WARNING: State Change ignored as there is no stateChange URL
  a request for activities
      Request Failed - Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')

Failures:

0) Verifying a pact between Foo Web Client and Activity Service - a request expecting null fields 
      Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

1) Verifying a pact between Foo Web Client 2 and Activity Service - a request for activities  Given many activities exist
      Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused)


> Task :killTheApp
killTheApp

We have completely different Gradle versions...

This is yours:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip

You can see in my original post, that Gradle 6.2.1 is used in my project.

Output in Gradle 6.2.1:

> Configure project :server:application
Evaluating project ':server:application' using build file '.../build.gradle'.

FAILURE: Build failed with an exception.

* Where:
Build file '.../build.gradle' line: 37

* What went wrong:
A problem occurred evaluating project ':server:application'.
> Could not get unknown property 'startAppForPactVerification' for au.com.dius.pact.provider.gradle.GradleProviderInfo@3e60bd5d[providerVersion=<null>,name=angus,protocol=http,host=build_83rkh6lgmc39pj1wppi6dws9$_run_closure3$_closure8$_closure10$_closure11@7afb903e,port=build_83rkh6lgmc39pj1wppi6dws9$_run_closure3$_closure8$_closure10$_closure12@6c6a1318,path=/,startProviderTask=<null>,terminateProviderTask=<null>,requestFilter=<null>,stateChangeRequestFilter=<null>,createClient=<null>,insecure=false,trustStore=<null>,trustStorePassword=changeit,stateChangeUrl=<null>,stateChangeUsesBody=true,stateChangeTeardown=false,isDependencyForPactVerify=true,verificationType=REQUEST_RESPONSE,packagesToScan=[],consumers=[]] of type au.com.dius.pact.provider.gradle.GradleProviderInfo.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 796ms

Ah, right! There are probably lots of things that are not going to work with Gradle 6 yet.

Ah, right! There are probably lots of things that are not going to work with Gradle 6 yet.

Cool! :D Fortunately, Gradle 7 is coming ;)

I've tested Gradle 6.0.1, 6.2.1 and 6.3. They all work ok with my test project without having to require any braces. There must be something else you are doing.

Could not get unknown property 'startAppForPactVerification' for au.com.dius.pact.provider.gradle.GradleProviderInfo

Is startAppForPactVerification the Gradle task?

I am sorry, but i can not give you any other information regarding the above.

I feel we are wasting time here, I'll set up a dummy project for testing purposes and share it with you here.

I think this way it's easier to understand what's going on with my code, chatting takes too much time.

This looks to be some weird Gradle issue. The problem is that the tasks are defined after the pact block. So it looks the without the braces the tasks need to be defined in the project at that point (moving them above the pact block fixes that issue). With the braces works when they are defined later. I don't understand what Gradle is doing, but I think it is maybe attaching a Closure to the verify task dependencies which only gets evaluated later.

Was this page helpful?
0 / 5 - 0 ratings