alex
alex

Reputation: 267

Adding module export to mvn test execution runtime

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

Upvotes: 4

Views: 7032

Answers (3)

alex
alex

Reputation: 267

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.

Upvotes: 2

tibor17
tibor17

Reputation: 1123

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.

Upvotes: 1

motzmann
motzmann

Reputation: 151

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.

Upvotes: 1

Related Questions