wiremock icon indicating copy to clipboard operation
wiremock copied to clipboard

Java 11: transitive dependency - NoSuchMethodError Google Collect during runtime (test execution) call of Wiremock#urlPathMatching / Wiremock#urlPathEqualTo

Open edgar-philipp opened this issue 5 years ago • 3 comments

Bug report

  • WireMock version 2.27.2 (used in test)
  • Spring Boot 2.4.1 (IMHO not relevant here)
  • JUnit5
  • Java 11

A failing test case that demonstrates the problem

    private static final int WIREMOCK_PORT = 9980;

    private WireMockServer wireMockServer;

    @BeforeEach
    public void setup () {
        wireMockServer = new WireMockServer(WIREMOCK_PORT);
        wireMockServer.start();
    }

    @AfterEach
    public void teardown () {
        wireMockServer.stop();
    }

	@Test
	public void testGetMetadata() {

		// Given
		wireMockServer.stubFor(get(urlPathMatching("/api/v1/users/.*/metadata"))
				.willReturn(aResponse()
						.withStatus(200)
						.withHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE)
						.withBody("{\"totalNumberOfTodos\":999,\"maxNumberOfTodos\":302}")));

      }

Stacktrace

"java.lang.NoSuchMethodError: 'com.google.common.collect.FluentIterable com.google.common.collect.FluentIterable.from(java.lang.Object[])'"

Stacktrace:

	at com.github.tomakehurst.wiremock.matching.StringValuePattern.getName(StringValuePattern.java:54)
	at com.github.tomakehurst.wiremock.matching.ContentPattern.<init>(ContentPattern.java:29)
	at com.github.tomakehurst.wiremock.matching.StringValuePattern.<init>(StringValuePattern.java:31)
	at com.github.tomakehurst.wiremock.matching.AnythingPattern.<init>(AnythingPattern.java:23)
	at com.github.tomakehurst.wiremock.matching.AnythingPattern.<init>(AnythingPattern.java:27)
	at com.github.tomakehurst.wiremock.matching.UrlPattern.<clinit>(UrlPattern.java:24)
	at com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo(WireMock.java:330)

edgar-philipp avatar Mar 02 '21 16:03 edgar-philipp

I've checked:

  • no com.google dependency in my pom
  • fails for both urlPathMatching and urlPathEqualTo

edgar-philipp avatar Mar 02 '21 16:03 edgar-philipp

NoSuchMethodError is usually the result of an incompatible library version appearing in your dependencies, rather than a WireMock bug.

I suggest you re-post this question on the mailing list and include full details of your setup including your full POM (or whatever equivalent you're using).

tomakehurst avatar Mar 02 '21 16:03 tomakehurst

I know this is closed now but I got it error and here is have I solved it. My maven dependency tree did not show a transient dependency to Guava from wiremock that was expected from the wiremock pom file that has a dependency to Guava.

My way out was to add a guava dependency it manual then it worked as expected.

Here is my dependency tree (mvn dependency:tree):

[INFO] - com.github.tomakehurst:wiremock-jre8:jar:2.27.2:test [INFO] +- org.eclipse.jetty:jetty-server:jar:9.4.28.v20200408:test [INFO] | +- org.eclipse.jetty:jetty-http:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-io:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-security:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-servlets:jar:9.4.28.v20200408:test [INFO] | +- org.eclipse.jetty:jetty-continuation:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-util:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-xml:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-proxy:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-client:jar:9.4.28.v20200408:test [INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.11.0:compile [INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.12:test [INFO] | - org.apache.httpcomponents:httpcore:jar:4.4.13:test [INFO] +- org.xmlunit:xmlunit-legacy:jar:2.7.0:test [INFO] +- org.xmlunit:xmlunit-placeholders:jar:2.7.0:test [INFO] +- org.ow2.asm:asm:jar:7.0:test [INFO] +- net.sf.jopt-simple:jopt-simple:jar:5.0.3:test [INFO] +- org.apache.commons:commons-lang3:jar:3.10:test [INFO] +- com.github.jknack:handlebars:jar:4.2.0:test [INFO] +- com.github.jknack:handlebars-helpers:jar:4.2.0:test [INFO] +- com.flipkart.zjsonpatch:zjsonpatch:jar:0.4.4:test [INFO] +- commons-fileupload:commons-fileupload:jar:1.4:test [INFO] | - commons-io:commons-io:jar:2.2:test [INFO] +- org.eclipse.jetty.http2:http2-server:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty.http2:http2-common:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty.http2:http2-hpack:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-alpn-server:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-alpn-conscrypt-server:jar:9.4.28.v20200408:test [INFO] +- org.eclipse.jetty:jetty-alpn-conscrypt-client:jar:9.4.28.v20200408:test [INFO] | - org.eclipse.jetty:jetty-alpn-client:jar:9.4.28.v20200408:test [INFO] +- org.conscrypt:conscrypt-openjdk-uber:jar:2.2.1:test [INFO] - net.javacrumbs.json-unit:json-unit-core:jar:2.12.0:test [INFO] - org.opentest4j:opentest4j:jar:1.1.1:test [INFO] ------------------------------------------------------------------------

softstuff avatar Mar 11 '21 17:03 softstuff