0
votes

I'm playing around with including Scala in my Java project.

I noticed that IntelliJ includes all of the following jars (extracted) in the generated runnable jar artifact:

scala-library-2.12.2.jar
scala-library-2.12.2-sources.jar
scala-reflect-2.12.2.jar
scala-reflect-2.12.2-sources.jar

Ignoring IDEs or build tools, I am curious as to whether all of these jars are actually required for running code that includes portions written in the Scala language.

I assume that, if I don't use any of the Scala libraries contained in these jars, compiled Scala code can actually run without them (I'm not claiming that it's a good idea - just curious).

So, my question is, which jars are required for what functionality and whether I should ALWAYS include all four jars in any application that uses Scala code.

To clarify, my question is only related to running the code, not building it.

1
Scala library is required. Scala reflect is the reflection library that may be required. The other two aren't technically required (they may need to be shipped as per the redistribution agreement) Scala library is always needed. Scala reflect only I'd you're using reflection, although you don't need to export them with the jar at all really if you are just talking about running the" binaries"Chris Maggiulli
@ChrisMaggiulli "Scala library" is scala-library-2.12.2.jar, "Scala reflect" is scala-reflect-2.12.2.jar, "the other two" are the sources? Under what circumstance would the sources be required for running the code?stepanian
@stepanian For running, they are not; for step-by-step debugging though...Elliott Frisch
@ElliottFrisch You mean debugging in production? If I'm using my IDE for debugging in production, which has the sources, then I'm OK, right?stepanian
Yes the other two are the source ones. The source is never required to run, but it is often required by the licensing / redistribution agreement. I use the term "required" a bit loosely though. Technically no jar files need to be repackaged like that because they can simply be extracted with the jar itself.Chris Maggiulli

1 Answers

2
votes

Quick Summary

The scala-library-2.12.2.jar is always "required". The Scala scala-reflect-2.12.2.jar is only required for projects that utilize reflection. The other two are exactly the same but with the source code also included in the package, those are never required to run the code.

A bit of clarification, technically the answer is none of those jars are required to run the code. This is because you do not technically need your dependencies to be packaged in jars inside your jar. Instead you can just choose to export the necessary class files with your project. However I think that's somewhat pedantic and a bit beyond what you're asking.

Also, be careful with the term "required" because often certain jar files are required to be repackaged as part of a licensing or redistribution agreement. This is not a technical requirement but rather a legal one.