Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21 support #2149

Open
oleg-nenashev opened this issue Apr 21, 2023 · 8 comments
Open

Java 21 support #2149

oleg-nenashev opened this issue Apr 21, 2023 · 8 comments
Labels
enhancement java Pull requests that update Java code

Comments

@oleg-nenashev
Copy link
Member

oleg-nenashev commented Apr 21, 2023

Proposal

Java 21 LTS is coming out soon, and it would be great to ensure that WireMock is fully compatible with it. WireMock may work out of the box, but we would still need official images, documentation, and CI runs against this baseline.

References

@oleg-nenashev oleg-nenashev added enhancement java Pull requests that update Java code labels Apr 21, 2023
@SimonVerhoeven
Copy link
Contributor

The Gradle wrapper will also need to be updated to 8.4.

@mikebell90
Copy link

Are there known issues ? It seems problematic to wait a year until after java 21 comes out for an official wiremock 4 support

@matiwinnetou
Copy link

matiwinnetou commented Nov 14, 2023

Doesn't seem compatible...

works with JDK 17 but fails with JDK 21

	testImplementation("org.wiremock:wiremock:3.3.1")

Error I am getting:

java.lang.IncompatibleClassChangeError: class org.eclipse.jetty.http2.server.HttpChannelOverHTTP2 has interface org.eclipse.jetty.server.HttpChannel as super class
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	at org.eclipse.jetty.http2.server.AbstractHTTP2ServerConnectionFactory.<init>(AbstractHTTP2ServerConnectionFactory.java:82)
	at org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory.<init>(HTTP2ServerConnectionFactory.java:53)
	at org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory.<init>(HTTP2CServerConnectionFactory.java:53)
	at org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory.<init>(HTTP2CServerConnectionFactory.java:48)
	at com.github.tomakehurst.wiremock.jetty11.Jetty11HttpServer.createHttpConnector(Jetty11HttpServer.java:53)
	at com.github.tomakehurst.wiremock.jetty.JettyHttpServer.<init>(JettyHttpServer.java:89)
	at com.github.tomakehurst.wiremock.jetty11.Jetty11HttpServer.<init>(Jetty11HttpServer.java:44)
	at com.github.tomakehurst.wiremock.jetty.JettyHttpServerFactory.buildHttpServer(JettyHttpServerFactory.java:31)
	at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:81)
	at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:123)
	at org.cardano.foundation.voting.api.BaseTest.setUp(BaseTest.java:62)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	Suppressed: java.lang.NullPointerException: Cannot invoke "com.github.tomakehurst.wiremock.WireMockServer.stop()" because "this.wireMockServer" is null
		at org.cardano.foundation.voting.api.BaseTest.tearDown(BaseTest.java:230)
		at java.base/java.lang.reflect.Method.invoke(Method.java:580)
		at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
		at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
		... 1 more

those lines are as simple as:

        wireMockServer = new WireMockServer(9090);
        wireMockServer.start();
mati@Mateuszs-MBP voting-ledger-follower-app % java --version
openjdk 21 2023-09-19 LTS
OpenJDK Runtime Environment Corretto-21.0.0.35.1 (build 21+35-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.0.35.1 (build 21+35-LTS, mixed mode, sharing)

@marcindabrowski
Copy link

marcindabrowski commented Nov 24, 2023

@matiwinnetou are you sure that in your project you are not importing any bom file? For example I had the same error with Spring Boot 3.2 because in their bom there is Jetty 12, which is not compatible with Jetty 11 used by Wiremock.

@seroandone
Copy link

@marcindabrowski how did you end up excluding springboot jetty bom? I am facing the same issue

@seroandone
Copy link

seroandone commented Dec 1, 2023

thanks for that info @marcindabrowski i was able to resolve it, here is what i did, added the following segment to my pom.xml

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-bom</artifactId>
      <version>11.0.18</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

This works, because, maven honors in the local pom.xml over the parent pom, or its parent.

Note: I am using,

  • java 21
  • springboot 3.2.0
  • wiremock 3.3.1

Documenting failure attempt,

tried changing just the value of <jetty.version> to 11.0.18 in of my pom.xml, however that wont work as there is another bom org.eclipse.jetty.ee10 that references the same <jetty.version> property, which doesn't have the same versioning.

Please comment if there was a better resolution

@marcindabrowski
Copy link

I'm using Gradle, and for me this helped:

configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.eclipse.jetty") {
            useVersion("11.0.18")
            because("Jetty 12.x.x from Spring Boot 3.2.x is incompatible with Wiremock 3.3.x.")
        }
    }
}

But it only works when you are importing Spring bom like this:

implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.0"))

If you are using io.spring.dependency-management Gradle plugin it will not work, becuase in Spring Boot 3.2.0 they added new Jetty depenedency jetty-ee10-bom, which do not have 11 version, and with this plugin you can just override Spring bom property like this:

ext["jetty.version"] = "11.0.18"

So the only solution I found is to remove this plugin and import Spring Bom in Gradle way.

@Saljack
Copy link

Saljack commented Dec 1, 2023

These mentioned errors are not connected to Java 21 but to library mismatch (Jetty in WireMock and Spring Booot).
But do not override jetty version or other hacky things. Just use wiremock-standalone:

<dependency>
    <groupId>org.wiremock</groupId>
    <artifactId>wiremock-standalone</artifactId>
    <version>3.3.1</version>
    <scope>test</scope>
</dependency>

This version shades all dependencies and you do not need to change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement java Pull requests that update Java code
Projects
Status: Must Have
Development

No branches or pull requests

7 participants