We have a requirement where we need our code base to be compiled with Java 17 and when the maven plugin generates artifacts it should be in Java 8 compatibility.
We are using sun.security.action.GetPropertyAction for security.
Maven plugin configurations are as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>--add-exports</arg>
<arg>java.base/sun.security.action=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/sun.security.action.GetPropertyAction =ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
When I run the mvn clean install I get the below error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project security: Fatal error compiling: error: option --add-exports not allowed with target 8 -> [Help 1]
When I remove the --add-exports option I get
[ERROR] package sun.security.action does not exist
[ERROR] /Users/security/ScriptPolicy.java:[182,41] cannot find symbol symbol: class GetPropertyAction
Could anyone help us with how I can generate a Java 8 compatible jar file when I am using Java 17 in my IntelliJ?