-
-
Notifications
You must be signed in to change notification settings - Fork 482
Description
I am currently using Pact JVM 4.1.29 and I was trying to upgrade to 4.6.17 version, but I'm struggling to do this due to some dependency conflicts.
When using Pact JVM 4.6.17, provider test modules require both Apache HttpClient 4.x and 5.x on the classpath. This causes classloader and reflection issues, such as:
java.lang.Exception: Method updateRequest should take only a single HttpRequest parameter
java.lang.NoClassDefFoundError: org/apache/hc/core5/http/HttpRequest
To Reproduce
Create a Maven project with the following dependencies:
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit</artifactId>
<version>4.6.17</version>
</dependency>
<dependency>
<groupId>au.com.dius.pact</groupId>
<artifactId>consumer</artifactId>
<version>4.6.17</version>
</dependency>
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit</artifactId>
<version>4.6.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.3</version>
</dependency>
Add a @TargetRequestFilter method in a provider test class:
@TargetRequestFilter
public void updateRequest(org.apache.http.HttpRequest request) {
request.setHeader("Authorization", "Basic test");
}
Run provider verification tests.
Expected behavior
- Provider tests should run successfully with @TargetRequestFilter using org.apache.http.HttpRequest (4.x) as parameter.
- No NoClassDefFoundError or annotation scanning errors should occur.
Actual behavior
-
If only HttpClient 4.x is present, I get:
java.lang.NoClassDefFoundError: org/apache/hc/core5/http/HttpRequest
-
If both HttpClient 4.x and 5.x are present, I get:
java.lang.Exception: Method updateRequest should take only a single HttpRequest parameter
-
If I exclude all 5.x dependencies, some Pact features and even core provider test functionality fail due to missing classes.
Additional context
- This makes it impossible to use Pact JVM 4.6.17 for provider verification tests in a stable way.
- The last known working version for provider is 4.1.29 (which does not reference HttpClient 5.x at all).
- I am seeking guidance on how to resolve this, or whether a future version will address the classpath conflict.
Versions
- Pact JVM: 4.6.17
- Apache HttpClient: 4.5.14 and/or 5.3.1
- Java: 17.0.11
- Build tool: Maven 3.6.3
Thank you!