Installing sbt

brew install coursier/formulas/coursier && cs setup

Setup build.sbt

Write following in build.sbt file in project directory.

scalaVersion := "3.0.0"
version := "1.0" // project version
 
name := "project-name"
organization := "com.tw"
 
libraryDependencies ++= Seq()

libraryDependencies for external dependencies.

Run sbt

Now, run sbt command. It will download and setup all the dependencies.

Setting up the directory structure

Create src directory in project root. This is the convention sbt uses.

src
├── main
│   └── scala
│       └── com
│           └── tw
│               └── Main.scala
└── test
    └── scala
        └── com
            └── tw
                └── SimpleTest.scala

Compile and run

sbt will open a console. Run compile command in there.

After this, run runMain com.tw.Main to run Main. Make sure Main has main method.

Conclusion

This is the simplest sbt scala project setup.

References