Pact JVM "au.com.dius.pact ... MismatchException" in CI
On the JVM, Pact reports verification failures as mismatches under the au.com.dius.pact packages. The stack trace or JUnit output names the interaction and the exact field that differs from the contract.
What this error means
A Gradle/Maven provider verification test fails with au.com.dius.pact... mismatch output, listing the interaction and the body path or status that did not match.
au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider
Verifying a pact between web-consumer and orders-provider
- a request for order 42
body: BodyMismatch: $.total Expected 19.99 but received 20.0Common causes
The provider response drifted from the pact
A controller now returns a different value, type, or field name than the recorded interaction expects.
The provider state was not applied
A missing @State method left the data unset, so the response did not match the state-dependent expectation.
How to fix it
Read the BodyMismatch and align
- Find the
BodyMismatch/StatusMismatchline and the JSON path it names. - Fix the provider response, or update and republish the consumer expectation.
- Ensure a
@Statemethod sets up each required provider state.
@State("order 42 exists")
void order42Exists() {
orderRepository.save(new Order(42, new BigDecimal("19.99")));
}Configure the broker source and provider version
Use @PactBroker with the provider version and branch so results publish and selectors resolve.
@PactBroker(url = "${PACT_BROKER_BASE_URL}")
// set pact.provider.version and pact.provider.branch system propertiesHow to prevent it
- Provide a
@Statemethod for every provider state in the pacts. - Set the provider version and branch system properties in CI.
- Use type matchers so valid variation does not fail JVM verification.