I am trying to create a multi-release jar with Maven (3.8.0). We call sun.misc.Unsafe
which compiles fine in java8 and java11. However, compiling with java11 --release 8
raises a Compilation failure: package sun.misc does not exist
.
Here is how to reproduce the error:
A simple class that calls Unsafe
:
public class ChangeableObjects {
sun.misc.Unsafe unsafe;
}
A simple pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
If we comment the <release>8</release>
line, it works fine on java8 and java11.
If we compile the code as is, it fails with java8; this is normal since it is a java9 feature. The problem is that it also fails with java11.
I assume the problem is that the sun.misc
package has been moved between java8 and java9. But still, the purpose of the release
flag is that a code that compiles well with java8 should also compile well with java11.
Am I misunderstanding how to use the release
flag? Do I need to link the sun.misc
package manually to make it work?