Building Scala 2.12 binaries from source code - scala

What is the complete sbt command to build scala 2.12.16 distributable binary for *Nix system (macOS & Linux)?
Scala 2.12.16 source zip : https://github.com/scala/scala/archive/refs/tags/v2.12.16.zip
PS: sbt publishLocal builds scala compiler of latest stable version and then publishes to local ivy2 repo. So it is not helpful for me.

Thanks Seth Tisue for providing git repo information.
git repo for building scala distributable binary https://github.com/scala/scala-dist.git
sbt command universal:packageBin
Complete command to build scala 2.12.x binaries from sources:
git clone https://github.com/scala/scala-dist.git
cd scala-dist
git checkout 2.12.x
sbt clean universal:packageBin
after firing the above command binaries will be present in target/universal/scala-2.12.16.zip

Related

How to install scala 2.12

There are multiple binary incompatible scala 2 versions, however the document says the installation is either via IDE or SBT.
DOWNLOAD SCALA 2
Then, install Scala:...either by installing an IDE such as IntelliJ, or sbt, Scala's build tool.
Spark 3 needs Scala 2.12.
Spark 3.1.2 uses Scala 2.12. You will need to use a compatible Scala version (2.12.x).
Then how can we make sure the scala version is 2.12 if we install sbt?
Or the documentation is not accurate and it should be "to use specific version of scala, need to download specific scala version on your own"?
Updates
As per the answer by mario-galic, in ONE-CLICK INSTALL FOR SCALA it is said:
Installing Scala has always been a task more challenging than necessary, with the potential to drive away beginners. Should I install Scala itself? sbt? Some other build tools? What about a better REPL like Ammonite? Oh and before all that I need to install Java?
To solve this problem, the Scala Center contracted Alexandre Archambault in January 2020 to add a one-click install of Scala through coursier. For example, on Linux, all we now need is:
$ curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup
The Scala version is specified in the build.sbt file so SBT will download the appropriate version of Scala as necessary.
I personally use SDKMAN! to install Java and then SBT.
The key concept to understand is the difference between system-wide installation and project-specific version. System-wide installation ends up somewhere on the PATH like
/usr/local/bin/scala
and can be installed in various ways, personally I recommend coursier one-click install for Scala
curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup
Project-specific version is specified by scalaVersion sbt settings which downloads Scala to coursier cache location. To see the Scala version and location used by the particular project try show scalaInstance which
inspect scalaInstance
[info] Task: sbt.internal.inc.ScalaInstance
[info] Description:
[info] Defines the Scala instance to use for compilation, running, and testing.
Scala should be binary compatible within minor version so Spark 3 or any other software built against any Scala 2.12.x version should work with any other Scala 2.12.x version where we have major.minor.patch. Note binary compatibility is not guaranteed for internal compiler APIs, so for example when publishing compiler plugins the best practice is to publish it against full specific Scala version. For example notice how kind-projector compiler plugin is published against full Scala version 2.13.6
https://repo1.maven.org/maven2/org/typelevel/kind-projector_2.13.6/
whilst scala-cats application-level library is published against any Scala 2.13.x version
https://repo1.maven.org/maven2/org/typelevel/cats-core_2.13/
Similarly spark is published against any Scala 2.12.x version
https://repo1.maven.org/maven2/org/apache/spark/spark-core_2.12/
Regarding system-wide installation one trick I do for quick switching of versions is to put scala-runners on the PATH and then different versions can be launched via --scala-version argument
scala --scala-version 2.12.14
Using coursier or scala-runners you can even switch JDK quickly via -C--jvm for example
scala --scala-version 2.12.14 -C--jvm=11
For a project, there should be no need to download manually a specific version of Scala. sbt either directly or indirectly via an IDE will download all the dependencies behind the scenes for you, so the only thing to specify is sbt setting scalaVersion.
Using Python as analogy to Scala, and Pipenv as anology to sbt, then python_version in Pipfile is similar to scalaVersion in build.sbt. After executing pipenv shell and pipenv install you end up with project-specific shell environment with project specific Python version and dependencies. sbt similarly downloads project specific Scala version and dependencies based of build.sbt although it has no need for lock files or for modifying your shell environment.

Scala.js 1.0.0-RC2 tests failing around jsdom

I'm the process of cross-building UnivEq for Scala.JS 1.0.0-RC2. I've got jsdom installed in Travis and tests pass on the 0.6.31 builds, but fail on the 1.0.0-RC2 builds with TypeError: jsdom.createVirtualConsole is not a function.
Full error log: https://travis-ci.org/japgolly/univeq/jobs/636731705#L312
How to fix? Please help.
This happens because we never ported the additional support of jsdom v12 and later from the Scala.js 0.6.x branch (in this commit) to the newer, separate codebase for JSDOMNodeJSEnv at https://github.com/scala-js/scala-js-env-jsdom-nodejs. Apparently we forgot about that.
I have created a pull request at https://github.com/scala-js/scala-js-env-jsdom-nodejs/pull/33 to fix the issue.
Edit: the fix is now published as version 1.0.0-RC3. You can modify your project/plugins.sbt to depend on "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.0.0-RC3" instead of ... % scalaJSVersion. It is compatible with Scala.js 1.0.0-RC2.
Obsolete old answer:
You could try using that new version today by checking out the master branch and publishing it locally:
$ git clone https://github.com/scala-js/scala-js-env-jsdom-nodejs.git
$ cd scala-js-env-jsdom-nodejs
$ sbt scalajs-env-jsdom-nodejs/publishLocal
$ cd ..
then using version 1.0.0-SNAPSHOT instead of 1.0.0-RC2 for scalajs-env-jsdom in your project/plugins.sbt

Install sbt from source

Because in my operating system distribution has not default package sbt, I try compile from source and install sbt package locally (https://github.com/sbt/sbt). Unfortunately I can not do it and I can not find any guide to do this without installed sbt. To compile sbt from source is needed sbt? What can I to do to install sbt from source?
The answer is yes: to build sbt from source, you need to install sbt first (obviously, not from source). There are instructions for Building sbt from source and they start with
Install the current stable binary release of sbt (see Setup), which will be used to build sbt from source.
If you have a concrete problem installing sbt from binaries, you should solve it first. You can ask for help with it in a new question.

"Error during sbt execution: No Scala version specified or detected" with SBT from Homebrew

I have installed Scala 2.10.3 and SBT 0.13.1. When I execute SBT following Hello, World from the SBT documentation I get the following error message:
"Error during sbt execution: No Scala version specified or detected"
I've tried to add a build.sbt file with the scalaVersion but the error keeps showing up.
Please advise.
I've just downgraded sbt to 0.12.3 and it works ... so what's wrong with 0.13.X ?
Its not an issue with the upgrade of 0.13.* version. Its the repository cache thats causing the issue. There are possibilities where you have broken / no ivys (when only the jar is downloaded through maven repo) for the sbt jars in your cache.
Once upgraded remove your ivy repo cache (or rename the folder) and remove the .sbt/boot folder (removing this will enable to start from the scratch)
Edit your ./sbt/repositories file and provide preference to the ivy repositories. If you are using proxy repositories which includes both ivy and maven style artifacts, the add it as below
[repositories]
local
maven-local
maven-central-ivy: http://<repository url>, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-central: http://<repository url>
This will enable especially (org.scala-sbt/sbt/*) to be download with the Ivys xml from where the version / revision and dependencies are picked up for the builds. If only the jar is downloaded from "maven-central", then the error occurs.
It is the problem of IDE you are using specially the scala plugin in it.
You can get ride of this just go to the folder where the build.sbt is created. Delete the "project" folder and open cmd, run "sbt" command on the folder, a new project folder will be created. Now you can open that in IDE.
It may be that you may find some problem very first in ide, if you build the project once , all the problems will go away.
I did exactly what #Gopi proposed but this is my repositories file content:
[repositories]
local
jcenter: https://jcenter.bintray.com/
maven-central
typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sbt-ivy-snapshots: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
My SBT Version: 1.1.1
java version 1.8
Windows 10
Hope that helps,
BR. Paul
I've also installed both Scala and SBT on my machine through homebrew and can just run the given simple hello example, so i guess you did something wrong :-)
Please provide a bit more diagnostics, for example:
What is the output of both commands 'which sbt' and 'which scala'?
You should see the results as below:
$ which scala
/usr/local/bin/scala
$ which sbt
/usr/local/bin/sbt
$ ls -laF /usr/local/bin/sbt
lrwxr-xr-x 1 rjk admin 28 Feb 9 13:32 /usr/local/bin/sbt# -> ../Cellar/sbt/0.13.1/bin/sbt
$ ls -laF /usr/local/bin/scala
lrwxr-xr-x 1 rjk admin 32 Feb 9 13:38 /usr/local/bin/scala# -> ../Cellar/scala/2.10.3/bin/scala
And given the directory where you ran the example code from, is it completely empty besides the hw.scala example? Or did you also add the build.sbt or project/build.properties? If that's the case it would be wise to also list that here to spot any problems with them.

Building apache Kafka

I am trying to build Kafka with Scala 2.10.1. I tried following steps given on Git-hub. At the end it generates a Jar in Target directory, however that Jar is empty and the size is 5kb. Am I missing something here ? I am totally new to SBT.
1) ./sbt update
2) ./sbt package
3) ./sbt assembly-package-dependency
To build for a particular version of Scala (either 2.8.0, 2.8.2, 2.9.1, 2.9.2 or 2.10.1), change step 2 above to: 2. ./sbt "++2.8.0 package"
Actually Kafka jar is located in core/target/scala-2.10/ directory, and dependencies are in the Ivy cache.
Execute ./sbt release-zip to get an archive in target/RELEASE/ with all dependencies and shell scripts packaged.
To build release for a particular Scala version, add version param to the build command:
./sbt "++2.10.1 release-zip"