What is Scala runtime, binary compatibility and how are Scala applications deployed?
These are three questions actually, but for me they are tightly connected.
What is Scala runtime? Is it just a regular JVM and a classpath to java-lang library? Can I run Scala applications on a plain JVM? Should I always deploy
scala-lang.jaralong with my own code?
Where does that
binary compatibilitycome from? The answer to this question usually sounds like:
Different Scala compilers produce different bytecode.
but this explains not much to me. Does it mean that the 'interface' of the bytecode is changed? Like changing the name of the field containing the instance of companion object, for example. If yes, then why is there no backward compatibility? Is not it possible to add metadata to the bytecode? Scala compiler could use it to change its behaviour/expectations and emit different bytecode for various versions.
- Does having library cross compiled for several Scala versions imply that using the library from Java will require its own interoperation for each version?
What is Scala runtime?
Yes, Scala runtime runs on top of JVM and all it needs is supporting
scala-lang.jarlibrary and "a plain" JVM of appropriate version. Scala code is compiled to JVM bytecode. You can see a bit more about what Scala compiler does here or you can check compilation phases.
And yes, when you want to run Scala code on JVM you should always provide
Where does that binary (in-)compatibility come from?
Scala compile actually is translate Scala source to Java bytecode with including scala-library.
So when deploy Scala in a plain JVM, need to include scala-library.jar like other dependencies.
For binary compatibility it means if Scala 2.12.2 is binary compatible with Scala 2.12.1, and project is compiled with Scala 2.12.1, you don't need to recompile project with Scala 2.12.2, it can run directly with Scala 2.12.2 library. and also it means if project has a dependency compiled in Scala 2.12.1, it can be safely used in Scala 2.12.2.