Skip to content

Commit 9e95472

Browse files
committed
Blend Scala 2 and Scala 3 “getting started” pages
- A lot of content is duplicated between those pages - Several people got confused by the fact that `cs setup` installs the Scala 2 compiler (`scalac`), but that command is enough to work with Scala 3 projects (since they usually use a build tool, which automatically uses the appropriate compiler version)
1 parent fe15458 commit 9e95472

File tree

6 files changed

+97
-228
lines changed

6 files changed

+97
-228
lines changed

_data/scala3-doc-nav-header.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- title: New in Scala 3
55
url: "/scala3/new-in-scala3.html"
66
- title: Getting Started
7-
url: "/scala3/getting-started.html"
7+
url: "/getting-started.html"
88
- title: Scala 3 Book
99
url: "/scala3/book/introduction.html"
1010
- title: Contributing Guide

_getting-started/index.md

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,32 @@ title: Getting Started
44
partof: getting-started
55
languages: [ja]
66
includeTOC: true
7+
scala3: true
78

8-
redirect_from: "/getting-started.html"
9+
redirect_from:
10+
- "/getting-started.html"
11+
- "/scala3/getting-started.html"
912
---
10-
## Try Scala without installing anything
11-
You can [try Scala in your browser](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA), with access to all Scala compilers and
12-
all published libraries.
1313

14-
## Install Scala
14+
## Try Scala without installing anything
15+
16+
To start experimenting with Scala right away, use <a href="https://scastie.scala-lang.org/pEBYc5VMT02wAGaDrfLnyw" target="_blank">“Scastie” in your browser</a>.
17+
_Scastie_ is an online “playground” where you can experiment with Scala examples to see how things work, with access to all Scala compilers and published libraries.
18+
19+
> Note that Scastie supports both Scala 2 and Scala 3, but it defaults
20+
> to Scala 3. If you are looking for a Scala 2 snippet to play with,
21+
> [click here](https://scastie.scala-lang.org/MHc7C9iiTbGfeSAvg8CKAA).
22+
23+
## Install Scala on your computer
24+
1525
Installing Scala means installing various command-line tools such as the Scala compiler and build tools.
16-
We recommend using the Scala installer tool that automatically installs all the requirements, but you can still manually install each tool.
26+
We recommend using the Scala installer tool "Coursier" that automatically installs all the requirements, but you can still manually install each tool.
1727

1828
### Using the Scala Installer (recommended way)
19-
The Scala installer is a tool named `cs` that ensures that a JVM and standard Scala tools are installed on your system.
2029

21-
* Download the `cs` tool and execute the `setup` command
30+
The Scala installer is a tool named [Coursier](https://get-coursier.io/docs/cli-overview), whose main command is named `cs`.
31+
It ensures that a JVM and standard Scala tools are installed on your system.
32+
Install it on your system with the following instructions.
2233

2334
<div class="main-download">
2435
<div id="download-step-one">
@@ -28,33 +39,57 @@ The Scala installer is a tool named `cs` that ensures that a JVM and standard Sc
2839
</div>
2940

3041

31-
Along with managing JVMs, it also installs useful command line tools:
32-
[Ammonite](https://ammonite.io/),
33-
[coursier](https://get-coursier.io/),
34-
scala (the Scala REPL and script runner),
35-
scalac (the Scala compiler),
36-
[sbt](https://www.scala-sbt.org/), and
37-
[scalafmt](https://scalameta.org/scalafmt/).
42+
Along with managing JVMs, `cs setup` also installs useful command-line tools:
43+
44+
- A JDK
45+
- The [sbt](https://www.scala-sbt.org/) build tool
46+
- [Ammonite](https://ammonite.io/), an enhanced REPL
47+
- [scalafmt](https://scalameta.org/scalafmt/), the Scala code formatter
48+
- `scalac` (the Scala 2 compiler)
49+
- `scala` (the Scala 2 REPL and script runner).
50+
51+
For more information about `cs`, read
52+
[coursier-cli documentation](https://get-coursier.io/docs/cli-overview).
53+
54+
> Currently, `cs setup` installs the Scala 2 compiler and runner (the `scalac` and
55+
> `scala` commands, respectively). This is usually not an issue because most projects
56+
> use a build tool that works with both Scala 2 and Scala 3.
57+
> Nevertheless, you can install the Scala 3 compiler and runner as command-line tools
58+
> by running the following additional commands:
59+
> ```
60+
> $ cs install scala3-compiler
61+
> $ cs install scala3
62+
> ```
3863
39-
For more information, read [coursier-cli documentation](https://get-coursier.io/docs/cli-overview).
64+
### ...or manually
65+
66+
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11,
67+
and sbt.
68+
To install them manually:
4069
41-
### ...Or manually
4270
1. if you don't have Java 8 or 11 installed, download
4371
Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html),
4472
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail.
4573
1. Install [sbt](https://www.scala-sbt.org/download.html)
4674
47-
## Create a Hello-world project with sbt
48-
To create a project, you can either use a command-line tool or an IDE.
75+
## Create a "Hello World" project with sbt
76+
77+
Once you have installed sbt, you are ready to create a Scala project, which
78+
is explained in the following sections.
79+
80+
To create a project, you can either use the command line or an IDE.
4981
If you are familiar with the command line, we recommend that approach.
5082
51-
### Using command-line
83+
### Using the command line
84+
5285
sbt is a build tool for Scala. sbt compiles, runs,
5386
and tests your Scala code. (It can also publish libraries and do many other tasks.)
5487
88+
To create a new Scala project with sbt:
89+
5590
1. `cd` to an empty folder.
56-
1. Run the following command `sbt new scala/hello-world.g8`.
57-
This pulls the 'hello-world' template from GitHub.
91+
1. Run the command `sbt new scala/scala3.g8` to create a Scala 3 project, or `sbt new scala/hello-world.g8` to create a Scala 2 project.
92+
This pulls a project template from GitHub.
5893
It will also create a `target` folder, which you can ignore.
5994
1. When prompted, name the application `hello-world`. This will
6095
create a project called "hello-world".
@@ -71,42 +106,69 @@ create a project called "hello-world".
71106
- Main.scala (Entry point of program) <-- this is all we need for now
72107
```
73108
74-
More documentation about sbt can be found in the [Scala Book](/overviews/scala-book/scala-build-tool-sbt.html)
109+
More documentation about sbt can be found in the [Scala Book](/scala3/book/tools-sbt.html) (see [here](/overviews/scala-book/scala-build-tool-sbt.html) for the Scala 2 version)
75110
and in the official sbt [documentation](https://www.scala-sbt.org/1.x/docs/index.html)
76111
77112
### With an IDE
78-
You can skip the rest of this page and go directly to [Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html#next-steps)
113+
114+
You can skip the rest of this page and go directly to [Building a Scala Project with IntelliJ and sbt](/getting-started/intellij-track/building-a-scala-project-with-intellij-and-sbt.html)
79115
80116
81117
## Open hello-world project
118+
82119
Let's use an IDE to open the project. The most popular ones are IntelliJ and VSCode.
83120
They both offer rich IDE features, but you can still use [many other editors.](https://scalameta.org/metals/docs/editors/overview.html)
121+
84122
### Using IntelliJ
123+
85124
1. Download and install [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/)
86125
1. Install the Scala plugin by following [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/managing-plugins.html)
87126
1. Open the `build.sbt` file then choose *Open as a project*
88127
89128
### Using VSCode with metals
129+
90130
1. Download [VSCode](https://code.visualstudio.com/Download)
91131
1. Install the Metals extension from [the Marketplace](https://marketplace.visualstudio.com/items?itemName=scalameta.metals)
92-
1. Next, open the directory containing a `build.sbt` file. When prompted to do so, select *Import build*.
132+
1. Next, open the directory containing a `build.sbt` file (this should be the directory `hello-world` if you followed the previous instructions). When prompted to do so, select *Import build*.
133+
134+
>[Metals](https://scalameta.org/metals) is a “Scala language server” that provides support for writing Scala code in VS Code and other editors like [Atom, Sublime Text, and more](https://scalameta.org/metals/docs/editors/overview.html), using the Language Server Protocol.
135+
>
136+
> Under the hood, Metals communicates with the build tool by using
137+
> the [Build Server Protocol (BSP)](https://build-server-protocol.github.io/). For details on how Metals works, see, [“Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”](https://www.scala-lang.org/2019/04/16/metals.html).
138+
139+
### Play with the source code
140+
141+
View these two files in your IDE:
142+
143+
- _build.sbt_
144+
- _src/main/scala/Main.scala_
145+
146+
When you run your project in the next step, the configuration in _build.sbt_ will be used to run the code in _src/main/scala/Main.scala_.
93147
94148
## Run Hello World
95-
Open a terminal
149+
150+
If you’re comfortable using your IDE, you can run the code in _Main.scala_ from your IDE.
151+
152+
Otherwise, you can run the application from a terminal with these steps:
153+
96154
1. `cd` into `hello-world`.
97-
1. Run `sbt`. This will open up the sbt console.
155+
1. Run `sbt`. This opens up the sbt console.
98156
1. Type `~run`. The `~` is optional and causes sbt to re-run on every file save,
99157
allowing for a fast edit/run/debug cycle. sbt will also generate a `target` directory
100158
which you can ignore.
101159
160+
When you’re finished experimenting with this project, press `[Enter]` to interrupt the `run` command.
161+
Then type `exit` or press `[Ctrl][d]` to exit sbt and return to your command line prompt.
102162
103163
## Next Steps
164+
104165
Once you've finished the above tutorials, consider checking out:
105166
106-
* [The Scala Book](/overviews/scala-book/introduction.html), which provides a set of short lessons introducing Scala’s main features.
167+
* [The Scala Book](/scala3/book/introduction.html) (see the Scala 2 version [here](/overviews/scala-book/introduction.html)), which provides a set of short lessons introducing Scala’s main features.
107168
* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
108169
* [Learning Resources](/learn.html), which includes online interactive tutorials and courses.
109170
* [Our list of some popular Scala books](/books.html).
171+
* [The migration guide](/scala3/guides/migration/compatibility-intro.html) helps you to migrate your existing Scala 2 code base to Scala 3.
110172
111173
## Getting Help
112174
There are a multitude of mailing lists and real-time chat rooms in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page for a list of these resources, and for where to reach out for help.
@@ -115,11 +177,11 @@ There are a multitude of mailing lists and real-time chat rooms in case you want
115177
-- This is handled in `resources/js/functions.js`.
116178
-->
117179
<div style="display:none" id="stepOne-linux">
118-
<code class="hljs">$ curl -Lo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup </code> <br>
180+
<code class="hljs">$ curl -fLo cs https://git.io/coursier-cli-linux && chmod +x cs && ./cs setup </code> <br>
119181
</div>
120182
121183
<div style="display:none" id="stepOne-unix">
122-
<p>Follow <a href="https://get-coursier.io/docs/cli-overview.html#install-native-launcher" target="_blank">the instructions to install the <code>cs</code> launcher</a> then run:</p>
184+
<p>Follow <a href="https://get-coursier.io/docs/cli-installation" target="_blank">the instructions to install the <code>cs</code> launcher</a> then run:</p>
123185
<p><code>$ ./cs setup</code></p>
124186
</div>
125187
@@ -129,7 +191,7 @@ There are a multitude of mailing lists and real-time chat rooms in case you want
129191
</div>
130192
<p>Alternatively, if you don't use Homebrew</p>
131193
<div class="highlight">
132-
<code class="hljs">$ curl -Lo cs https://git.io/coursier-cli-macos && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup </code> <br>
194+
<code class="hljs">$ curl -fLo cs https://git.io/coursier-cli-macos && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup</code> <br>
133195
</div>
134196
</div>
135197

_overviews/scala3-book/tools-sbt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,4 @@ For more information about sbt and ScalaTest, see the following resources:
510510
511511
512512
513-
[getting_started]: {{ site.baseurl }}/scala3/getting-started.html
513+
[getting_started]: {{ site.baseurl }}/getting-started.html

index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ scala3-sections:
1717
- title: "Getting Started"
1818
description: "Install Scala 3 on your computer and start writing some Scala code!"
1919
icon: "fa fa-rocket"
20-
link: /scala3/getting-started.html
20+
link: /getting-started.html
2121
- title: "Scala 3 Book"
2222
description: "An online book introducing the main language features."
2323
icon: "fa fa-book"

0 commit comments

Comments
 (0)