How to use Java options in Spring Boot pom file?

419 Views Asked by At

I am getting an error when I try to run the integration test (@SpringBootTest) in my application. I got a solution to use below the Java option

--add-opens java.base/java.nio=ALL-UNNAMED

I have checked it by editing the run configuration and it is working completely. (Run test case with above argument)

But I want to add through the pom file so when I run mvn clean install then it should work. I have tried this but it didn't work.

     <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <jvmArguments>
                    --add-opens java.base/java.nio=ALL-UNNAMED
                </jvmArguments>
            </configuration>
      </plugin>

I have also checked -Djava.base/java.nio=ALL-UNNAMED It is also not working. What is the right way to use this JVM argument so it can set runtime?

1

There are 1 best solutions below

1
On

spring-boot-maven-plugin doesn't run your tests. It's Maven's Surefire plugin that does that. You need to configure its argLine property:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>--add-opens java.base/java.nio=ALL-UNNAMED</argLine>
  </configuration>
</plugin>