Skip to content
Latchkey

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.

Pact JVM
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.0

Common 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

  1. Find the BodyMismatch/StatusMismatch line and the JSON path it names.
  2. Fix the provider response, or update and republish the consumer expectation.
  3. Ensure a @State method sets up each required provider state.
ProviderVerificationTest.java
@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.

ProviderVerificationTest.java
@PactBroker(url = "${PACT_BROKER_BASE_URL}")
// set pact.provider.version and pact.provider.branch system properties

How to prevent it

  • Provide a @State method 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →