Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass --add-opens JDK module configuration to maven test

I'm upgrading java version in our production code from java 8 to java 11.

I have to add the below JDK module configuration in the application java start command due to usage of third party libraries like flume, zookeeper etc.

--add-opens java.base/java.lang=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED

After adding this configuration and java application is starting fine.

But when I run the tests using mvn test the tests are failing. I've added the below configuration to the maven-surefire-plugin but still it is throwing error.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
        <argLine>--illegal-access=permit</argLine>
        <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
        <argLine>--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED</argLine>
        <argLine>-Dillegal-access=permit</argLine>
    </configuration>
</plugin>

I think I'm not passing the argument correctly in the maven test. Any idea what I'm doing wrong and how to fix this?

like image 771
Rajkumar Natarajan Avatar asked Nov 19 '20 21:11

Rajkumar Natarajan


People also ask

How do you use -- add opens?

--add-opens Some libraries do deep reflection, meaning setAccessible(true) , so they can access all members, including private ones. You can grant this access using the --add-opens option on the java command line. No warning messages are generated as a result of using this option.

What is the minimum version of Java for Maven?

2.1. The Maven compiler accepts this command with –target and –source versions. If we want to use the Java 8 language features, the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8. The default value for both of them is the 1.6 version.

How to add additional Java files to a Maven project?

Maven compiles the source code file (s) and then tests the source code file (s). Then Maven runs the test cases. Finally, Maven creates the package. Now open the command console, go the C:\MVN\consumerBanking arget\classes directory and execute the following java command. Hello World! Let's see how we can add additional Java files in our project.

How do I start a Maven project from the console?

By default, Maven adds a source file App.java and a test file AppTest.java in its default directory structure, as discussed in the previous chapter. Let's open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command. Maven will start building the project. [INFO] Scanning for projects...

How do I run a test file in Maven?

By default, Maven adds a source file App.java and a test file AppTest.java in its default directory structure, as discussed in the previous chapter. Let's open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command.

What version of Java do I need for Maven?

Until Java 8, we used the version number as 1. x where x represents Java's version, like 1.8 for Java 8. For Java 9 and above, we can just use the version number directly: Similarly, we can define the version using properties as: Maven added its support for Java 9 in 3.5.0, so we'll need at least that version.


1 Answers

It is a single argLine, like:

<argLine>
    --add-exports org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
    --add-exports org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
</argLine>
like image 122
Eugene Avatar answered Oct 08 '22 04:10

Eugene