Skip to content

Commit 93c3bf0

Browse files
committed
Redirect 'Getting started' links to docs.scala-lang.org
1 parent d101068 commit 93c3bf0

6 files changed

+12
-439
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,5 @@
11
---
22
title: Building a Scala Project with IntelliJ and sbt
3-
layout: inner-page-no-masthead
4-
disqus: true
5-
previous-page: getting-started-intellij-track/getting-started-with-scala-in-intellij
6-
next-page: testing-scala-in-intellij-with-scalatest
3+
redirect_to:
4+
- https://docs.scala-lang.org/getting-started-intellij-track/building-a-scala-project-with-intellij-and-sbt.html
75
---
8-
9-
In this tutorial, we'll see how to build a Scala project using [sbt](http://www.scala-sbt.org/0.13/docs/index.html). sbt is a popular tool for compiling, running, and testing Scala projects of any
10-
size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies
11-
or more than one code file.
12-
We assume you've completed the
13-
[first tutorial]({{ site.baseurl }}/documentation/getting-started-intellij-track/getting-started-with-scala-in-intellij.html).
14-
15-
## Creating the project
16-
In this section, we'll show you how to create the project in IntelliJ. However, if you're
17-
comfortable with the command line, we recommend you try [Getting
18-
Started with Scala and sbt on the Command Line]({{site.baseurl}}/documentation/getting-started-sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html) and then come back
19-
20-
here to the section "Writing Scala code".
21-
22-
1. If you didn't create the project from the command line, open up IntelliJ and select "Create New Project"
23-
* On the left panel, select Scala and on the right panel, select SBT
24-
* Click **Next**
25-
* Name the project "sbtExampleProject"
26-
* If you already created the project on the command line, open up IntelliJ, select *Import Project* and open the `build.sbt` file for your project
27-
* Make sure the **JDK Version** is 1.8 and the **SBT Version** is at least 0.13.13
28-
* Select **Use auto-import** so dependencies are automatically downloaded when available
29-
* Select **Finish**
30-
31-
## Understanding the directory structure
32-
sbt creates many directories which can be useful once you start building
33-
more complex projects. You can ignore most of them for now
34-
but here's a glance at what everything is for:
35-
36-
```
37-
- .idea (IntelliJ files)
38-
- project (plugins and additional settings for sbt)
39-
- src (source files)
40-
- main (application code)
41-
- java (Java source files)
42-
- scala (Scala source files) <-- This is all we need for now
43-
- scala-2.12 (Scala 2.12 specific files)
44-
- test (unit tests)
45-
- target (generated files)
46-
- build.sbt (build definition file for sbt)
47-
```
48-
49-
50-
## Writing Scala code
51-
1. On the **Project** panel on the left, expand `sbtExampleProject` => `src`
52-
=> `main`
53-
* Right-click `scala` and select **New** => **Package**
54-
* Name the package `example` and click **OK**.
55-
* Right-click the package `example` and select **New** => **Scala class**.
56-
* Name the class `Main` and change the **Kind** to `object`.
57-
* Change the code in the class to the following:
58-
59-
```
60-
object Main extends App {
61-
val ages = Seq(42, 75, 29, 64)
62-
println(s"The oldest person is ${ages.max}")
63-
}
64-
```
65-
66-
Note: IntelliJ has its own syntax highlighter and sometimes your code is
67-
correct even though IntelliJ indicates otherwise. You can always check
68-
to see if sbt can run your project on the command line.
69-
70-
## Running the project
71-
1. From the **Run** menu, select **Edit configurations**
72-
* Click the **+** button and select **SBT Task**.
73-
* Name it `Run the program`.
74-
* In the **Tasks** field, type `~run`. The `~` causes sbt to rebuild and rerun the project
75-
when you save changes to a file in the project.
76-
* Click **OK**.
77-
* On the **Run** menu. Click **Run 'Run the program'**.
78-
* In the code, change `64` to `99`
79-
and look at the updated output in the console.
80-
81-
## Adding a dependency
82-
Changing gears a bit, let's look at how to use published libraries to add
83-
extra functionality to our apps.
84-
1. Open up `build.sbt` and add the following line:
85-
86-
```
87-
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
88-
89-
```
90-
Here, `libraryDependencies` is a set of dependencies, and by using `+=`,
91-
we're adding the [scala-parser-combinators](https://index.scala-lang.org/scala/scala-parser-combinators) dependency to the set of dependencies that sbt will go
92-
and fetch when it starts up. Now, in any Scala file, you can import classes,
93-
objects, etc, from scala-parser-combinators with a regular import.
94-
95-
Find published libraries at [Scaladex](https://index.scala-lang.org/).
96-
97-
## Next steps
98-
Continue learning the language for free online with
99-
[Scala Exercises](http://www.scala-exercises.org).
100-
You can also check out our [list of learning resources](http://scala-lang.org/documentation/).
101-
102-
[Up Next: Testing Scala in IntelliJ with scalatest]({{ site.baseurl }}/documentation/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.html)
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,5 @@
11
---
22
title: Getting Started with Scala in IntelliJ
3-
layout: inner-page-no-masthead
4-
disqus: true
5-
next-page: building-a-scala-project-with-intellij-and-sbt
3+
redirect_to:
4+
- https://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html
65
---
7-
8-
In this tutorial, we'll see how to build a minimal Scala project
9-
using IntelliJ IDE with the Scala plugin. We'll have IntelliJ download
10-
Scala for you.
11-
12-
## Installation
13-
1. Make sure you have the Java 8 JDK (also known as 1.8)
14-
* Run `javac -version` on the command line and make sure you see
15-
`javac 1.8.___`
16-
* If you don't have version 1.8 or higher, [install the JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
17-
1. Install [IntelliJ Community Edition](https://www.jetbrains.com/idea/download/)
18-
1. Install the Scala plugin by following the instructions on
19-
20-
[how to install IntelliJ plugins](https://www.jetbrains.com/help/idea/installing-updating-and-uninstalling-repository-plugins.html)
21-
22-
When we create the project, we'll install the latest version of Scala.
23-
Note: If you want to open an existing Scala project, you can click **Open**
24-
when you start IntelliJ.
25-
26-
## Creating the Project
27-
1. Open up IntelliJ and click **File** => **New** => **Project**
28-
* On the left panel, select Scala. On the right panel, select Scala once again. If Scala is not an option, select SBT.
29-
* Name the project **HelloWorld**
30-
* Assuming this is your first time creating a Scala project with IntelliJ,
31-
you'll need to install a Scala SDK. To the right of the Scala SDK field,
32-
click the **Create** button.
33-
* Select the highest version number (e.g. 2.12.1) and click **Download**. This might
34-
take a few minutes but subsequent projects can use the same SDK.
35-
* Once the SDK is created and you're back to the "New Project" window click **Finish**.
36-
37-
## Writing code
38-
39-
1. On the **Project** pane on the left, right-click `scala` folder under src/main and select
40-
**New** => **Scala class**.
41-
42-
* Name the class `Hello` and change the **Kind** to `object`.
43-
* Change the code in the class to the following:
44-
45-
```
46-
object Hello extends App {
47-
println("Hello, World!")
48-
}
49-
```
50-
51-
## Running it
52-
* Right click on `Hello` in your code and select **Run 'Hello'**.
53-
* You're done!
54-
55-
## Experimenting with Scala
56-
A good way to try out code samples is with Scala Worksheets
57-
58-
1. In the project pane on the left, right click
59-
`src` and select **New** => **Scala Worksheet**.
60-
* Enter the following code into the worksheet:
61-
62-
```
63-
def square(x: Int) = x * x
64-
65-
square(2)
66-
```
67-
68-
As you change your code, you'll notice that it gets evaluated
69-
in the right pane.
70-
71-
## Next Steps
72-
Now you know how to create a simple Scala project which can be used
73-
for starting to learn the language. In the next tutorial, we'll introduce
74-
an important build tool called sbt which can be used for simple projects
75-
and production apps.
76-
77-
78-
Up next: [Building a Scala project with IntelliJ and sbt]({{ site.baseurl }}/documentation/getting-started-intellij-track/building-a-scala-project-with-intellij-and-sbt.html)
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,5 @@
11
---
22
title: Testing Scala in IntelliJ with ScalaTest
3-
layout: inner-page-no-masthead
4-
disqus: true
5-
previous-page: building-a-scala-project-with-intellij-and-sbt
3+
redirect_to:
4+
- https://docs.scala-lang.org/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.html
65
---
7-
8-
There are multiple libraries and testing methodologies for Scala,
9-
but in this tutorial, we'll demonstrate one popular option from the ScalaTest framework
10-
called [FunSuite](http://www.scalatest.org/getting_started_with_fun_suite).
11-
12-
We assume you know [how to build a project in IntelliJ]({{ site.baseurl }}/documentation/getting-started-intellij-track/building-a-scala-project-with-intellij-and-sbt.html).
13-
14-
## Setup
15-
1. Create an sbt project in IntelliJ.
16-
* Add the ScalaTest dependency to your build.sbt file:
17-
18-
```
19-
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
20-
```
21-
* this will cause sbt to pull down the ScalaTest library
22-
* If you get a notification "build.sbt was changed", select **auto-import**.
23-
* On the project pane on the left, expand `src` => `main`.
24-
* Right-click on `scala` and select **New** => **Scala class**.
25-
* Call it `CubeCalculator`, change the **Kind** to `object`, and click **OK**.
26-
* Replace the code with the following:
27-
28-
```
29-
object CubeCalculator extends App {
30-
def cube(x: Int) = {
31-
x * x * x
32-
}
33-
}
34-
```
35-
36-
## Creating a test
37-
1. On the project pane on the left, expand `src` => `test`.
38-
39-
* Right-click on `scala` and select **New** => **Scala class**.
40-
* Name the class `CubeCalculatorTest` and click **OK**.
41-
* Replace the code with the following:
42-
43-
```
44-
import org.scalatest.FunSuite
45-
46-
class CubeCalculatorTest extends FunSuite {
47-
test("CubeCalculator.cube") {
48-
assert(CubeCalculator.cube(3) === 27)
49-
}
50-
}
51-
```
52-
53-
* In the source code, right-click `CubeCalculatorTest` and select **Run 'CubeCalculatorTest'**.
54-
55-
## Understanding the code
56-
Let's go over this line by line.
57-
58-
* `class CubeCalculatorTest` means we are testing the object `CubeCalculator`
59-
* `extends FunSuite` lets us use functionality of ScalaTest's FunSuite class
60-
such as the `test` function
61-
* `test` is function that comes from the FunSuite library that collects
62-
results from assertions within the function body.
63-
* `"CubeCalculator.cube"` is a name for the test. You can call it anything but
64-
one convention is "ClassName.methodName".
65-
* `assert` takes a boolean condition and determines whether the test passes or fails.
66-
* `CubeCalculator.cube(3) === 27` checks whether the output of the `cube` function is
67-
indeed 27. The `===` is part of ScalaTest and provides clean error messages.
68-
69-
## Adding another test case
70-
71-
* Add another `assert` statement after the first one that checks for the cube
72-
of `0`.
73-
* Re-run the test again by right-clicking `CubeCalculatorTest` and selecting
74-
'Run **CubeCalculatorTest**'.
75-
76-
## Conclusion
77-
You've seen one way to test your Scala code. You can learn more about
78-
ScalaTest's FunSuite on the [official website](http://www.scalatest.org/getting_started_with_fun_suite).
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,5 @@
11
---
22
title: Getting Started with Scala and sbt on the Command Line
3-
layout: inner-page-no-masthead
4-
disqus: true
5-
redirect_from:
6-
- documentation/getting-started-sbt-track/getting-started-with-scala-and-sbt-in-the-command-line.html
7-
next-page: testing-scala-with-sbt-on-the-command-line
3+
redirect_to:
4+
- https://docs.scala-lang.org/getting-started-sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html
85
---
9-
10-
In this tutorial, you'll see how to create a Scala project from
11-
a template. You can use this as a starting point for your own
12-
projects. We'll use [sbt](http://www.scala-sbt.org/0.13/docs/index.html), the de facto build tool for Scala. sbt compiles,
13-
runs, and tests your projects among other related tasks.
14-
We assume you know how to use a terminal.
15-
16-
## Installation
17-
18-
1. Make sure you have the Java 8 JDK (also known as 1.8)
19-
* Run `javac -version` on the command line and make sure you see
20-
`javac 1.8.___`
21-
* If you don't have version 1.8 or higher, [install the JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
22-
23-
2. Install sbt
24-
* [Mac](http://www.scala-sbt.org/0.13/docs/Installing-sbt-on-Mac.html)
25-
* [Windows](http://www.scala-sbt.org/0.13/docs/Installing-sbt-on-Windows.html)
26-
* [Linux](http://www.scala-sbt.org/0.13/docs/Installing-sbt-on-Linux.html)
27-
28-
## Create the project
29-
1. `cd` to an empty folder.
30-
* Run the following command `sbt new scala/hello-world.g8`.
31-
This pulls the 'hello-world' template from GitHub.
32-
It will also create a `target` folder, which you can ignore.
33-
* When prompted, name the application `hello-world`. This will
34-
create a project called "hello-world".
35-
* Let's take a look at what just got generated
36-
37-
```
38-
- hello-world
39-
- project (sbt uses this to install manage plugins and dependencies)
40-
- build.properties
41-
- src
42-
- main
43-
- scala (All of your scala code goes here)
44-
-Main.scala (Entry point of program) <-- this is all we need for now
45-
build.sbt (sbt's build definition file)
46-
47-
```
48-
49-
After you build your project, sbt will create more `target` directories
50-
for generated files. You can ignore these.
51-
52-
## Running the project
53-
1. `cd` into `hello-world`.
54-
* Run `sbt`. This will open up the sbt console.
55-
* Type `~run`. The `~` is optional and causes sbt to re-run on every file save,
56-
57-
allowing for a fast edit/run/debug cycle. sbt will also generate a `target` directory
58-
which you can ignore.
59-
60-
## Modifying the code
61-
1. Open the file `src/main/scala/Main.scala` in your favorite text editor.
62-
63-
* Change "Hello, World!" to "Hello, New York!"
64-
* If you haven't stopped the sbt command, you should see "Hello, New York!"
65-
printed to the console.
66-
* You can continue to make changes and see the results.
67-
68-
69-
## Adding a dependency
70-
Changing gears a bit, let's look at how to use published libraries to add
71-
extra functionality to our apps.
72-
73-
1. Open up `build.sbt` and add the following line anywhere in the file:
74-
75-
```
76-
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
77-
```
78-
79-
Here, `libraryDependencies` is a set of dependencies, and by using `+=`,
80-
we're adding the [scala-parser-combinators](https://index.scala-lang.org/scala/scala-parser-combinators) dependency to the set of dependencies that sbt will go
81-
and fetch when it starts up. Now, in any Scala file, you can import classes,
82-
objects, etc, from scala-parser-combinators with a regular import.
83-
84-
Find published libraries at [Scaladex](https://index.scala-lang.org/).
85-
86-
## Next steps
87-
Now that you know how to create a Scala project, you
88-
can continue learning online for free with [Scala Exercises](http://scala-exercises.org) or choose
89-
from our [list of educational resources](http://scala-lang.org/documentation/).
90-
91-
[Up Next: Testing Scala with sbt on the command line]({{ site.baseurl }}/documentation/getting-started-sbt-track/testing-scala-with-sbt-on-the-command-line.html)

0 commit comments

Comments
 (0)