davidB / scala-maven-plugin

The scala-maven-plugin (previously maven-scala-plugin) is used for compiling/testing/running/documenting scala code in maven.
https://davidb.github.io/scala-maven-plugin/
The Unlicense
560 stars 151 forks source link

Build error on `sun.*` APIs when `-release` Java version is lower than the execution Java version #722

Open LuciferYang opened 1 year ago

LuciferYang commented 1 year ago

Here is the simplest reproducible example: https://github.com/LuciferYang/scala-maven-plugin-test

The reproducible code is very simple:

package personal.code

import sun.util.calendar.ZoneInfo

import java.util.TimeZone

object TestUtils {
  def doTest(): Boolean = TimeZone.getDefault.isInstanceOf[ZoneInfo]
}

run

git clone git@github.com:LuciferYang/scala-maven-plugin-test.git
cd scala-maven-plugin-test
mvn clean install  -X // Use versions higher than Java 11, such as use Java 17 to run maven clean install

We can see the following compilation error:

[DEBUG] [zinc] The Scala compiler is invoked with:
        -unchecked
        -deprecation
        -feature
        -explaintypes
        -target:11
        -release
        11
        -bootclasspath
        /Users/yangjie01/.m2/repository/org/scala-lang/scala-library/2.13.11/scala-library-2.13.11.jar
        -classpath
        /Users/yangjie01/SourceCode/git/scala-maven-plugin-test/target/classes:/Users/yangjie01/.m2/repository/org/scala-lang/scala-reflect/2.13.11/scala-reflect-2.13.11.jar:/Users/yangjie01/.m2/repository/org/scala-lang/scala-compiler/2.13.11/scala-compiler-2.13.11.jar:/Users/yangjie01/.m2/repository/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar:/Users/yangjie01/.m2/repository/org/jline/jline/3.22.0/jline-3.22.0.jar:/Users/yangjie01/.m2/repository/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar:/Users/yangjie01/.m2/repository/org/scala-lang/scala-library/2.13.11/scala-library-2.13.11.jar
[WARNING] [Warn] : -target is deprecated: Use -release instead to compile against the correct platform API.
[ERROR] [Error] /Users/yangjie01/SourceCode/git/scala-maven-plugin-test/src/main/scala/personal/code/TestUtils.scala:3: object util is not a member of package sun
[ERROR] [Error] /Users/yangjie01/SourceCode/git/scala-maven-plugin-test/src/main/scala/personal/code/TestUtils.scala:8: not found: type ZoneInfo
[WARNING] one warning found
[ERROR] two errors found
[DEBUG] Compilation failed (CompilerInterface)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.368 s
[INFO] Finished at: 2023-09-12T19:53:26+08:00
[INFO] ------------------------------------------------------------------------

mvn clean install -Dscala-maven-plugin.version=4.8.0 and mvn clean install -Dscala-maven-plugin.version=4.7.2 will have the same error.

mvn clean install -Dscala-maven-plugin.version=4.7.1 will build success

The -release option is automatically appended after https://github.com/davidB/scala-maven-plugin/pull/648.

Maybe we need to add an new option that doesn’t enforce appending -release when it’s false?

LuciferYang commented 1 year ago

friendly ping @slandelle for this issue, I don’t know enough about the details of this project yet, do you think it’s rational to add a toggle for the automatically appending -release option? Or what would be a more reasonable solution?

dongjoon-hyun commented 1 year ago

Thank you, @LuciferYang .