You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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)
Copy file name to clipboardExpand all lines: _getting-started/index.md
+93-31Lines changed: 93 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,32 @@ title: Getting Started
4
4
partof: getting-started
5
5
languages: [ja]
6
6
includeTOC: true
7
+
scala3: true
7
8
8
-
redirect_from: "/getting-started.html"
9
+
redirect_from:
10
+
- "/getting-started.html"
11
+
- "/scala3/getting-started.html"
9
12
---
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.
13
13
14
-
## Install Scala
14
+
## Try Scala without installing anything
15
+
16
+
To start experimenting with Scala right away, use <ahref="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,
> 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
+
> ```
38
63
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:
40
69
41
-
### ...Or manually
42
70
1. if you don't have Java 8 or 11 installed, download
43
71
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),
44
72
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail.
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.
49
81
If you are familiar with the command line, we recommend that approach.
50
82
51
-
### Using command-line
83
+
### Using the command line
84
+
52
85
sbt is a build tool for Scala. sbt compiles, runs,
53
86
and tests your Scala code. (It can also publish libraries and do many other tasks.)
54
87
88
+
To create a new Scala project with sbt:
89
+
55
90
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.
58
93
It will also create a `target` folder, which you can ignore.
59
94
1. When prompted, name the application `hello-world`. This will
60
95
create a project called "hello-world".
@@ -71,42 +106,69 @@ create a project called "hello-world".
71
106
- Main.scala (Entry point of program) <-- this is all we need for now
72
107
```
73
108
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)
75
110
and in the official sbt [documentation](https://www.scala-sbt.org/1.x/docs/index.html)
76
111
77
112
### 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)
79
115
80
116
81
117
## Open hello-world project
118
+
82
119
Let's use an IDE to open the project. The most popular ones are IntelliJ and VSCode.
83
120
They both offer rich IDE features, but you can still use [many other editors.](https://scalameta.org/metals/docs/editors/overview.html)
121
+
84
122
### Using IntelliJ
123
+
85
124
1. Download and install [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/)
86
125
1. Install the Scala plugin by following [the instructions on how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/managing-plugins.html)
87
126
1. Open the `build.sbt` file then choose *Open as a project*
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_.
93
147
94
148
## 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
+
96
154
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.
98
156
1. Type `~run`. The `~` is optional and causes sbt to re-run on every file save,
99
157
allowing for a fast edit/run/debug cycle. sbt will also generate a `target` directory
100
158
which you can ignore.
101
159
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.
102
162
103
163
## Next Steps
164
+
104
165
Once you've finished the above tutorials, consider checking out:
105
166
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.
107
168
* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
108
169
* [Learning Resources](/learn.html), which includes online interactive tutorials and courses.
109
170
* [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.
110
172
111
173
## Getting Help
112
174
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
115
177
-- This is handled in `resources/js/functions.js`.
<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>
123
185
<p><code>$ ./cs setup</code></p>
124
186
</div>
125
187
@@ -129,7 +191,7 @@ There are a multitude of mailing lists and real-time chat rooms in case you want
0 commit comments