Java 17 Maven Compiler is not allowed with --release error

772 views Asked by At

I want to use google-java-format plugin in my code.For that reason I added some exports configuration to my pom inside the maven compiler plugin and after run clean install process I got error.I try this command outside of the idea and using maven command via over commandline.

exporting a package from system module jdk.compiler is not allowed with --release

Regards

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven.compiler.version}</version>
        <configuration>
          <!--<release>${maven.compiler.target}</release>-->
          <compilerArgs>
            <arg> --add-opens=java.base/java.lang=ALL-UNNAMED</arg>
            <arg>--add-opens=java.base/java.util=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
            <arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
          </compilerArgs>

        </configuration>
      </plugin>
3

There are 3 answers

0
cgf On

I hit the same issue with spring boot 3.1.x and java 17. The compiler argument "--add-exports" no longer working with spring boot 3.1.x.

Spring boot up to version 3.0.9 works ok with that compiler argument, but 3.1.x versions all fail (3.1.0, 3.1.1, 3.1.2).

0
木原金 On

use:

<maven.compiler.release></maven.compiler.release>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

see:

https://github.com/spring-projects/spring-boot/issues/37993

0
Bilgehan On

create a jvm.config file and put it under the .mvn folder so it covers maven builds

--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED 
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED 
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED 
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED 
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED