we have a Scala (2.13.8) project where we use the java.net.http.HttpClient
to resolve a simple Rest call.
Until the project was built using SBT there was no issue. Since we moved to Maven, we are encountering the following runtime error:
cannot access class jdk.internal.net.http.HttpRequestBuilderImpl (in module java.net.http) because module java.net.http does not export jdk.internal.net.http to unnamed module
Since we create a fat-jar out of the project, we managed to solve the issue passing the following additional parameter to the CLI command:
java --add-exports java.net.http/jdk.internal.net.http=ALL-UNNAMED -jar abc.jar
The reason why we moved back to Maven was due to issues in handling Log4j2 with the SBT build. Now in Maven we are using the scala-maven-plugin
as following:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.7.1</version>
<configuration>
<scalaVersion>2.13.8</scalaVersion>
<args>
<arg>-language:higherKinds</arg>
<arg>-explaintypes</arg>
<arg>-deprecation</arg>
<!-- optimizations -->
<arg>-optimize</arg>
<arg>-opt:unreachable-code</arg>
<arg>-opt:box-unbox</arg>
<arg>-opt:l:inline</arg>
<arg>-opt-inline-from:**</arg>
<arg>-target:11</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
What are we doing wrong compared to the working out-of-the-box SBT build where everything was working just fine (not even targeting the specific JDK 11)? In that case there was no need of --add-exports
parameter, and everything could run also from IntelliJ directly (now we can's).
p.s. Before you redirect me to other posts, IntelliJ is already configured to target the JDK 11 and use the SDK 11 in the whole project (and also general settings).
Thank you in advance for any clarification.