Skip to content

One click install for Scala #1130

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

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions _posts/2020-03-23-one-click-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: blog-detail
post-type: blog
by: Sébastien Doeraene
title: "One-click install for Scala"
---

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](https://get-coursier.io/docs/cli-overview).
For example, on Linux, all we now need is:

```bash
$ curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup
```

which will install all the following software, if not yet installed:

* a JDK
* the build tools [sbt](https://www.scala-sbt.org/) and [mill](https://www.lihaoyi.com/mill/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding sbt, would this install the same launcher script and launcher JAR as what one would get using downloading the installer or using SDKMAN?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installs a launcher for the coursier-based sbt launcher, based on this "app descriptor".

You can generate one locally with cs bootstrap sbt-launcher -o sbt for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be very misleading to call any alternative packaging of sbt as sbt on novice user's PATH since inevitably they will run into some incompatibilities of handling SBT_OPTS environment variable or dependency resolution difference etc, and then whoever in the position of supporting the person in-house, or in open source would have to reverse-engineer "ok. what sbt script are you using, and how did it get to your PATH?"

I'm more than happy to use Coursier for all three layers (launcher, plugins, proper build), but I think it should happen in conjunction with the official (preloaded) distribution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example in Bash script incompatibility (likely parsing of SBT_OPTS):

$ ./sbt
[info] Loading settings for project global-plugins from idea.sbt,vimquit.sbt,plugins.sbt,pgp.sbt ...
[info] Loading global plugins from /Users/eed3si9n/.sbt/1.0/plugins
[info] Loading project definition from /Users/eed3si9n/work/sbt-coursier/project/project
[info] Loading settings for project sbt-coursier-build from plugins.sbt ...
[info] Loading project definition from /Users/eed3si9n/work/sbt-coursier/project
[info] Loading settings for project sbt-coursier-root from build.sbt ...
[info] Set current project to sbt-coursier-root (in build file:/Users/eed3si9n/work/sbt-coursier/)
[error] Expected ';'
[error] -Xms2048M
[error]          ^

Copy link

@alexarchambault alexarchambault Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of cs bootstrap sbt-launcher -o sbt (basically, what is installed by cs setup or cs install sbt-launcher) doesn't read SBT_OPTS. Not sure how you can get that error.

If you used the custom sbt-extras script linked from the README, it should basically be the same handling as sbt-extras mainline. But it's not what's installed by the one-click install here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it came up on Gitter just now that somebody was using the coursier-based launcher and wasn't getting their .jvmopts, in case there's any doubt this will bite people in practice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, the user in question opened a ticket: coursier/sbt-launcher#167

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, cs setup now installs an sbt launcher based on sbt/launcher. If you already installed sbt via cs setup or cs install, remove it and install sbt again, like

$ cs uninstall sbt
$ cs install sbt

It still doesn't read .jvmopts though. It handles a few of the options of sbt-extras via coursier/sbt-runner (that parses some options upfront, then calls the main class of sbt/launcher).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Is there a reason cs update sbt would not work?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's because the name of the "app descriptor" changed from sbt-launcher to sbt. The uninstall-then-install steps allow to pull the newer app descriptor.

Just sbt now works, as if one uses it with an explicit version, it does correspond to an actual sbt version as expected. This gives cs launch sbt:1.3.10 -- new scala/scala-seed.g8. This works because the new app descriptor references org.scala-sbt:sbt-launch directly. With the former one, the explicit version would have applied to just coursier/sbt-launcher, whose versions are not in sync with sbt. cs launch sbt-launcher:1.2.21 felt slightly less odd than cs launch sbt:1.2.21. That problem went away now.

* the [Ammonite](https://ammonite.io/) enhanced REPL
* [scalafmt](https://scalameta.org/scalafmt/), the Scala formatter
* the [coursier](https://get-coursier.io/docs/cli-overview) CLI, to install further Scala-based applications
* the `scala` and `scalac` command-line tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some details about how we manage specific versions of scala and scalac, and how to update the cs tool itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as well.


With all those installed, we are ready to go!
Later, `cs update` can be used to update the installation.

For power users, [the `cs setup` command](https://get-coursier.io/docs/cli-setup) offers more configuration options, such as a non-interactive mode.

With this new simple, all-encompassing installer, we at the Scala Center hope to significantly reduce the burden of getting started with Scala.