Skip to content

There are difference between maven.compiler.release and maven.compiler.target during compiling projects which use sun.misc.Unsafe with JDK17+ #990

@zrlw

Description

@zrlw

Affected version

3.14.0, 3.14.1

Bug description

There are import sun.misc.Unsafe; in our codes, we want the target class bytecode version is java 8 for the sake of compatibility.

During runing mvn compile with jdk17+,

  1. we will encounter Cannot compile: java: package sun.misc does not exist ERROR and the compilation process will be terminated with failure if we set maven.compiler.release to 8
  <properties>
    <maven.compiler.release>8</maven.compiler.release>
  </properties>

or configure release of maven-compiler-plugin to 8 at the pom.xml like this,

    <profile>
      <id>jdk9-compile</id>
      <activation>
        <jdk>[1.9,)</jdk>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <release>8</release>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  1. Unsafe is internal proprietary API and may be removed in a future release Warning will appear and the compilation process will continue if we set maven.compiler.target to 1.8 at the pom.xml (delete jdk9-compile profile configuration) like this,
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions