Skip to content
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

[2.x] Recipe for hello world #1235

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/reference/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
- [Caching](concepts/caching.md)
- [Reference]()
- [Remote cache setup](reference/remote-cache-setup.md)
- [Recipes]()
- [Write hello world](recipes/hello-world.md)
- [Appendix]()
- [Setup notes](setup-notes.md)
42 changes: 42 additions & 0 deletions src/reference/recipes/hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
How to write hello world
========================

Problem
-------

I want to write a hello world program in Scala, and run it.

Steps
-----

1. Create a fresh directory, like `hello_scala/`
2. Create a directory named `project/` under `hello_scala/`, and create `project/build.properties` with
```
sbt.version={{sbt_version}}
```
3. Under `hello_scala/`, create `build.sbt`:
```scala
scalaVersion := "{{scala3_example_version}}"
```
4. Under `hello_scala/`, create `Hello.scala`:
```scala
@main def main(args: String*): Unit =
println(s"Hello ${args.mkString}")
```
5. Navigate to `hello_scala/` from the terminal, and run `sbt`:
```bash
$ sbt
```
6. When the prompt appears, type `run`:
```scala
sbt:hello_scala> run
```
7. Type `exit` to exit the sbt shell:
```scala
sbt:hello_scala> exit
```

Alternatives
------------

When you're in a hurry, you can run `sbt init` in a fresh directory, and select the first template.