Java Maven Error Invalid Flag --add-opens

Viewed 45

I implemented GSON in my program (Java (16), Maven). I encountered the "InaccessibleObjectException" and by research I found out I had to add "add-opens ..." to the vm command line. Eventually I got the program running and working by adding it. But now I have the issue, once I restart my program in my IDE (intelliJ) I get the error message java: error: invalid flag: --add-opens java.base/java.time=ALL-UNNAMED.

Weird thing is, this doesn't even happen all the time, it feels like it is random because sometimes I can restart my program without any issues and I can fix it by deleting it, restarting, adding it, restarting again.. I am absolutely clueless hence I made this account here. How can I fix this?

My pom build looks like this

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <jvm.options>--add-opens java.base/java.time=ALL-UNNAMED</jvm.options>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>16</source>
                    <target>16</target>
                    <compilerArgs>
                        <arg>${jvm.options}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.14.0</version>
                <configuration>
                    <sourceEncoding>utf-8</sourceEncoding>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>1.9</targetJdk>
                    <excludes>
                        <exclude>**/*Bean.java</exclude>
                        <exclude>**/generated/*.java</exclude>
                    </excludes>
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/stubs</excludeRoot>
                    </excludeRoots>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>${jvm.options}</argLine>
                </configuration>
                </plugin>
            <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
                <configuration>
                    <argLine>${jvm.options}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>
0 Answers
Related