|
2 | 2 | title: Scala CLI as scala
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -# Scala CLI as implementation for `scala` command |
| 5 | +# Scala CLI as an implementation of the `scala` command |
6 | 6 |
|
7 |
| -Scala CLI is designed to be a replacement for script that is currently installed as `scala`. Since Scala CLI is |
8 |
| -feature-packed we do not want to expose all the features and options to the whole Scala public at the very start. Why is |
9 |
| -that? |
| 7 | +As of Scala 3.5.0, Scala CLI has become the official runner for the language, |
| 8 | +replacing the old runner implementation under the `scala` script. |
10 | 9 |
|
11 |
| -- We want to make sure that the options / commands are stable |
12 |
| -- We do not want to overwhelm users with multiple options and commands |
13 |
| -- We want to make sure that the commands we add to `scala` are stable so once we commited to supporting given option it |
14 |
| - may be hard to remove it later |
| 10 | +Since Scala CLI is quite feature-packed, we do not want to expose all the features and options to all the Scala users |
| 11 | +from the very beginning. Why is that? |
| 12 | + |
| 13 | +- We want to make sure that the options / commands are stable. |
| 14 | +- We do not want to overwhelm users with multiple options and commands. |
15 | 15 |
|
16 | 16 | That is why we built in a mechanism to limit the commands, options, directives in Scala CLI by default. However, it's
|
17 | 17 | still possible to enable all features by explicitly passing the `--power` flag on the command line, or by setting it
|
18 | 18 | globally running:
|
19 | 19 |
|
20 | 20 | ```bash ignore
|
21 |
| -scala-cli config power true |
| 21 | +scala config power true |
| 22 | +``` |
| 23 | + |
| 24 | +Alternatively, it is also possible to rely on the `SCALA_CLI_POWER` environment variable to achieve the same: |
| 25 | + |
| 26 | +```bash ignore |
| 27 | +export SCALA_CLI_POWER=true |
22 | 28 | ```
|
23 | 29 |
|
24 | 30 | To check which options, commands and directives are supported when running Scala CLI with limited functionalities, refer
|
25 | 31 | to [options](./cli-options.md), [commands](./commands.md) and [using directives](./directives.md), respectively.
|
26 | 32 |
|
27 |
| -## Testing Scala CLI as `scala` |
| 33 | +## Installing Scala CLI as `scala` |
| 34 | + |
| 35 | +Refer to the [official instructions for installing Scala](https://www.scala-lang.org/download/). |
| 36 | + |
| 37 | +:::note |
| 38 | +A given Scala version has a paired Scala CLI version which is used by the `scala` command installed alongside it, as per |
| 39 | +the [official instructions](https://www.scala-lang.org/download/). |
| 40 | +This means that even when installing the latest Scala version, its `scala` command may refer to an older Scala CLI |
| 41 | +version. |
28 | 42 |
|
29 |
| -There are two recommended ways to test and use Scala CLI: |
| 43 | +To get the latest stable Scala CLI launcher, refer to the [separate |
| 44 | +`scala-cli` installation instructions](../../../install). |
30 | 45 |
|
31 |
| -- with brew: |
| 46 | +Alternatively, you can use the `--cli-version` launcher option to specify the Scala CLI version to use. |
| 47 | +This will run the JVM launcher of the specified Scala CLI version under the hood, so do keep in mind that it may be a |
| 48 | +bit slower than a native launcher. |
| 49 | +Also, the specified version (and potentially any of its dependencies, if they are not already installed) would be |
| 50 | +downloaded if it's not available in the local cache, so it may require additional setup for isolated environments. |
32 | 51 |
|
33 | 52 | ```bash ignore
|
34 |
| -brew install virtuslab/scala-experimental/scala |
| 53 | +scala --cli-version 1.5.0 version |
| 54 | +# Scala CLI version: 1.5.0 |
| 55 | +# Scala version (default): 3.5.0 |
35 | 56 | ```
|
36 | 57 |
|
37 |
| -- with coursier: |
| 58 | +If the bleeding edge is what you are after, you can use the nightly version this way. |
| 59 | +Just keep in mind that there are no guarantees about the stability of nightly versions. |
38 | 60 |
|
39 | 61 | ```bash ignore
|
40 |
| -cs setup |
41 |
| -cs install scala-experimental ← this command will replace the default scala runner |
| 62 | +scala --cli-version nightly version |
| 63 | +# Scala CLI version: 1.5.0-17-g00e4c88c1-SNAPSHOT |
| 64 | +# Scala version (default): 3.5.0 |
42 | 65 | ```
|
43 | 66 |
|
44 |
| -Alternatively, you can rename your `scala-cli` executable or alias it as `scala`. |
| 67 | +::: |
45 | 68 |
|
46 | 69 | ## Migrating from the old `scala` runner to Scala CLI
|
47 | 70 |
|
48 | 71 | If you have been using the old `scala` runner and want to migrate to Scala CLI, refer
|
49 | 72 | to [the migration guide](../../guides/introduction/old-runner-migration.md).
|
| 73 | + |
| 74 | +## Using the old (deprecated) `scala` runner with Scala 3.5+ |
| 75 | + |
| 76 | +You can still use the (deprecated as of Scala 3.5.0) legacy runner with Scala 3.5+ installed. It is available under |
| 77 | +the `scala_legacy` command. |
| 78 | + |
| 79 | +:::caution |
| 80 | +Even though this enables usage of the old runner under a new alias, it is recommended to |
| 81 | +migrate any existing scripts and automations to Scala CLI under either `scala` or `scala-cli`, as the `scala_legacy` |
| 82 | +command may be dropped at some point in the future. |
| 83 | +::: |
| 84 | + |
| 85 | +```bash ignore |
| 86 | +scala_legacy |
| 87 | +# [warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work. |
| 88 | +# [warning] Please be sure to update to the Scala CLI launcher to use the new features. |
| 89 | +# [warning] Check the Scala 3.5.0 release notes to troubleshoot your installation. |
| 90 | +# Welcome to Scala 3.5.0 (17, Java OpenJDK 64-Bit Server VM). |
| 91 | +# Type in expressions for evaluation. Or try :help. |
| 92 | +# |
| 93 | +# scala> |
| 94 | +``` |
0 commit comments