Hi, all. This is a question about `pact-gradle-plu...
# pact-jvm
i
Hi, all. This is a question about
pact-gradle-plugin
. What I want to achieve - two separate gradle tasks for running provider test a) using contracts fetched from broker; b) using contract file on local file system. For now I have one for pact broker:
Copy code
pact {

	broker {
		pactBrokerUrl = 'url'

		pactBrokerToken = 'token' 
	}

	serviceProviders {
		MyProvider {



            ....


			fromPactBroker {
				withSelectors {
					// Some selectors
				}
			}
		}
	}
}
I’ve tried: 1. Add another provider MyProviderLocal under
serviceProviders
with specifying path to local pact file 2. Add new gradle task and put inside
pact
dsl:
Copy code
task pactLocal {
    pact {
       ......
    }
}
Both attempts not working, it recognise
broker
block and always trying to get pacts from broker.
u
The
pact
block is global and not task specific. There are two ways you can do it, if you want to have two different verification tasks, you can use different provider names (MyProvider and MyProviderLocal), or if you want only a single provider name, you can setup two different sources and they will both be verified as part of the same task.
i
@uglyog Adding MyProviderLocal into
serviceProviders
doesn’t work - as
broker
block defined at top level, plugin tries to find provider named
MyProviderLocal
directly in broker, and of course, it not exists. I want to run single option - broker or local contracts, so, do not suppose to have two sources at one place.
Error example:
Caused by: <http://au.com|au.com>.dius.pact.core.pactbroker.NotFoundHalResponse: No HAL document found at path '<https://secretescapes.pactflow.io/pacts/provider/MyProviderLocal/for-verification>'
If I would define
broker
block on the fly in command line, not in
build.gradle
directly, it could resolve my issue. Seems like presence of
broker
block orders to search for all providers in broker
BTW, we use
4.1.39
version of
<http://au.com|au.com>.dius.pact
due to version limitations of Gradle and Java
u
Use an if statement based on a project property. Then set the property on the command line
i
Thank you, I’ll try
@uglyog That helped, thank you. It works in this way:
Copy code
if(useBroker="true") {
    broker {
        ....
    }
}
And then run
./graldew pactVerify_FlashsalesLocal -PuseBroker=false
👏 1