3

Getting this error during tests:

class javax.crypto.JceSecurity (in unnamed module @0x45da40ad) cannot access class jdk.internal.util.StaticProperty (in module java.base) because module java.base does not export jdk.internal.util to unnamed module @0x45da40ad

I've tried creating jvm.config at the root, next to pom.xml as such

--add-modules ALL-SYSTEM
--add-opens java.base/jdk.internal.util=ALL-UNNAMED
--illegal-access=permit

That doesn't change anything. So i try to configure maven compiler plugin as such:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <fork>true</fork>
    <compilerArgs>
      <arg>--add-modules</arg>
      <arg>ALL-SYSTEM</arg>
      <arg>--add-opens</arg>
      <arg>java.base/jdk.internal.util=ALL-UNNAMED</arg>
    </compilerArgs>
    <argLine>
      --add-modules ALL-SYSTEM
      --add-opens java.base/jdk.internal.util=ALL-UNNAMED
      --illegal-access=permit
    </argLine>
    <source>${java.compiler.source}</source>
    <target>${java.compiler.target}</target>
    </configuration>
</plugin>

for the record i even tried it so:

<argLine>
  --add-modules ALL-SYSTEM
  --add-opens java.base/jdk.internal.util=ALL-UNNAMED
  --illegal-access=permit
</argLine>

Nothing. Then i tried surefire plugin like so :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M5</version>
  <configuration>
    <forkCount>0</forkCount>
    <argLine>
      --add-modules ALL-SYSTEM
      --add-opens java.base/jdk.internal.util=ALL-UNNAMED
      --illegal-access=permit
    </argLine>
    <systemPropertyVariables>
      <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
    </systemPropertyVariables>
  </configuration>
</plugin>

Two days working on this and failing miserably. Please help. Using OpenJdk11

gawi
  • 2,843
  • 4
  • 29
  • 44
alex
  • 227
  • 3
  • 11

3 Answers3

1

I cross checked with surefire 3.0.0-M3 and -M5 and it should be absolutely sufficient to configure surefire with add-opens Oracle's Migration Guide

Also your format is absolutely correct: --add-opens <module>/<package>=ALL-UNNAMED. In Combination with --illegal-access=permit it should work fine.

I see only one more option: remove =ALL-UNNAMED from your opens-argument, this will crash the VM/ Surefire and proves your settings are active.

Beyond that your test classes ought to be invoked through reflection by your favorite runner (test method package private/ without public-modifier). This requires the same opens-declaration for your test classes/ cause the same issues – unless the Maven project isn't a module itself.

Maybe clarify this in your question.

motzmann
  • 151
  • 6
  • Project and test-classes are not configured as modules. They run fine under jdk8 with mvn clean install. Fail only when i change system jdk to openjdk11 – alex Nov 12 '20 at 17:55
  • The whole codename Jigsaw module concept was introduced with Java 9 and overhauled in 11 (with additional fixes in 14). So there are at least three different scenarios: JDK 8 works fine, Java 9 shows warnings, Java 11 failes. It is still odd, that argLine has to be in properties. Something is wrong with your surefire-plugin setup. Did you check imported and parent poms? – motzmann Nov 13 '20 at 07:54
1

Many tutorials and guides publish the following workaround

<forkCount>0</forkCount>

Please do not use it!

The surefire subprocess is A MUST especially in JPMS.

Please do not apply the workaround with forkCount=0 and rather report a bug in the Apache JIRA and communicate with the open source developers.

tibor17
  • 1,043
  • 6
  • 9
0

Thank to the other answers, it helped me to dig deeper. I managed to solve it with the following changes in pom

<properties>
        <!-- Must be in pom's properties section. <sonar.jacoco.reportPaths>target/coverage.exec</sonar.jacoco.reportPaths> -->
        <jacoco.version>0.7.7.201606060606</jacoco.version>
<!--         Used by surefire plugin run tests with openjdk11 -->
        <argLine>--add-modules java.base --add-opens java.base/jdk.internal.util=ALL-UNNAMED --illegal-access=permit</argLine>
    </properties>
.........
 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.compiler.source}</source>
                    <target>${java.compiler.target}</target>
                </configuration>
            </plugin>
........
<plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.2</version>
                        <configuration>
                            <systemPropertyVariables>
                                <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>

Basically i had to put the argline in properties. Compiler doesn't seem to need it because it's not picking it up from there. But surefire does, it's reading the argline from maven's properties.

walen
  • 7,103
  • 2
  • 37
  • 58
alex
  • 227
  • 3
  • 11
  • 1
    The argLine is specific only to Surefire and Failsafe plugin. Not the compiler plugin. Everyting you put there would appear on the JVM process CLI arguments. There CLI arguments are eager. Personally i would fetch the absolute path to jacoco-agent.destfile and use it in argLine. The section systemPropertyVariables is not eager and sets the properties in Java code lately after the JVM has already started. This may be a problem for JaCoCo. – tibor17 Nov 13 '20 at 08:32