maven icon indicating copy to clipboard operation
maven copied to clipboard

after migration from jdk17 to jdk21 junit is failing and ignoring surefire arling arguments for --add-open java.lang and junit fails throwing InaccessbleObjectException

Open kavita369 opened this issue 1 year ago • 5 comments

Affected version

jdk21 maven version is 3.9.9 maven-compiler-plugin.version=3.14.0,Jacoco Version 0.8.11, aven Surefire Plugin 3.1.2

Bug description

We have migrated our springboot project from jdk17 to jdk21. In pom I have changed 1. jdk version to 21, 2. <maven-compiler-plugin.version>3.14.0 3. jacoco.version> 0.8.11 in and has --add-open java.base/java.lang=All-UNNAMED. This pom has reference to pom which in turn has springboot-starter-parent defined as tag with version as 3.2.5. 3 junits are failing with InAccessibleObjectException related to reflection. which we otherwise passing during clean intall with jdk17 and --add-open option defined in pom. are the version correct for jdk21

kavita369 avatar Nov 06 '25 05:11 kavita369

I took help of github.maven chat and used following in my pom.xml

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.11</version>
  <executions>
    <execution>
      <id>prepare-agent</id>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>test</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.1.2</version>
  <configuration>
    <argLine>${jacoco.argLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
  </configuration>
</plugin>

still junit is failing and --add-opens is ignored

kavita369 avatar Nov 06 '25 06:11 kavita369

@kavita369 Hello maam, I would like to solve this issue plss assign me

Jayesh45-master avatar Dec 28 '25 10:12 Jayesh45-master

@kavita369 Hello Maam i have raised an pull request to solve this issue can you plss review it it would be helpful

Jayesh45-master avatar Dec 28 '25 10:12 Jayesh45-master

I fill that it is not a problem in Maven itself but rather in project.

Can you provide a simple project which can reproduce your issue?

slawekjaranowski avatar Jan 25 '26 15:01 slawekjaranowski

The use of --add-opens java.base/java.lang=ALL-UNNAMED is strongly discouraged. This is really asking for trouble, as the Java platform is progressively becoming more and more strict on integrity with new releases.

desruisseaux avatar Feb 07 '26 11:02 desruisseaux