Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary compatibility with JDK 9 #2951

Merged
merged 2 commits into from
Feb 5, 2017
Merged

Conversation

retronym
Copy link
Member

@retronym retronym commented Feb 5, 2017

This pull request cleans up two small issues that stood in the way of using the soon-to-be-released Java 9 with SBT.

  • No more java.ext.dirs
  • java.xml.bind not part of the java.base default classpath

Scala compiler versions prior to 2.12.1 do not tolerate the absence of rt.jar from the JDK. But we can appease them a little manual setup.

First, we can extract an equivalent JAR with a tool I've written:

% git clone https://github.com/retronym/java9-rt-export
% cd java9-rt-export/
% java_use 1.8
% sbt package
% java_use 9
% mkdir -p $HOME/.sbt/0.13/java9-rt-ext; java -jar target/java9-rt-export-*.jar $HOME/.sbt/0.13/java9-rt-ext/rt.jar
% jar tf $HOME/.sbt/0.13/java9-rt-ext/rt.jar | grep java/lang/Object

Then, we can feed that to the compilation classpath of Scala compilers used within SBT with the scala.ext.dirs System property.

% java_use 9
% sbt -Dscala.ext.dirs=$HOME/.sbt/0.13/java9-rt-ext clean compile console
[info] Loading global plugins from /Users/jason/.sbt/0.13/plugins
[info] Compiling 1 Scala source to /Users/jason/.sbt/0.13/plugins/target/scala-2.10/sbt-0.13/classes...
[info] Loading project definition from /Users/jason/code/scratch1/project
[info] Set current project to scratch1 (in build file:/Users/jason/code/scratch1/)
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:crossScalaVersions and 13 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] Set current project to scratch1 (in build file:/Users/jason/code/scratch1/)
[success] Total time: 0 s, completed 4 Feb. 2017, 10:37:59 pm
[info] Updating {file:/Users/jason/code/scratch1/}scratch1...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source and 1 Java source to /Users/jason/code/scratch1/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.8. Compiling...
[info]   Compilation completed in 7.315 s
[success] Total time: 9 s, completed 4 Feb. 2017, 10:38:08 pm
[info] Compiling 1 Scala source to /Users/jason/code/scratch1/target/scala-2.11/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea).
Type in expressions for evaluation. Or try :help.

scala> java.lang.invoke.VarHandle.fullFence _
res0: () => Unit = <function0>

Note that this doesn't actually require you to use Scala 2.12.1 in your application, 2.11.8 is able to use Java 9.

Also note that scalac does not yet enforce the stricter module accessibility rules imposed by JEP-261, so your code might typecheck and compile but incur LinkageError-s at runtime if you are calling non-exported APIs.

This is the start of an effort to make SBT 0.13.x compatible
with JDK 9.

The system property java.ext.dirs no longer exists now that
JEP-220 has removed the extension and endorsed classpath
facilities. It is also forbidden to manually set this to
an empty string from the command line.

This commit treats the absense of this property as an
empty extension classpath.
JEP-201 describes the new modularized Java Standard Library in Java 9.
By default, java.xml.bind is no longer on the default classpath; it needs
to be added explicitly with a JVM option `--add-modules java.xml.bind`,
or with a dependency declaration in the module-info.java file if you
package your own code up as a Jigsaw module.

This commit traps the linkage error and (reflectively) uses the
java.util.Base64, which is the recommended way to encode/decode
since 1.8.
@dwijnand dwijnand merged commit 756151f into sbt:0.13 Feb 5, 2017
@dwijnand
Copy link
Member

dwijnand commented Feb 6, 2017

Notes in #2952

@eed3si9n
Copy link
Member

We need to forward port these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants