Preliminary compatibility with JDK 9 #2951

merged 2 commits into from Feb 5, 2017


None yet
3 participants

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
% 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...
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.

retronym added some commits Feb 5, 2017

Future proof against removal of java.ext.dirs in Java 9
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.
Future proof for java.xml.bind removal from Java 9 default 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 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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

@dwijnand dwijnand removed the in progress label Feb 5, 2017


This comment has been minimized.

Show comment
Hide comment

dwijnand Feb 6, 2017


Notes in #2952


dwijnand commented Feb 6, 2017

Notes in #2952


This comment has been minimized.

Show comment
Hide comment

eed3si9n Feb 14, 2017


We need to forward port these.


eed3si9n commented Feb 14, 2017

We need to forward port these.

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