For macOS:
brew install Virtuslab/scala-cli/scala-cliFor Linux:
curl -sSLf https://scala-cli.virtuslab.org/get | shFor Windows:
winget install virtuslab.scalacliIf some of the above methods does not work, visit the official installation page.
You can check this Scala-CLI mini guide to get up to speed.
If you use IntelliJ Idea, VS Code or any other alternative that uses Metals, then run the following command so scala-cli generates the Build Server Protocol (BSP) Json file needed for your IDE to understand the Scala files.
scala-cli setup-ide . --scala <your_scala_version>More information about IDE support here.
Once you are located in the root folder of the project, you can do many things with Scala-CLI. The usual suspects are:
In the presence of the directive //> using target.scope test in a test file, the option --power has to be
included in the Scala-CLI command.
To compile the current folder - every file inside, run:
scala-cli --power compile .To compile only the test files, you need to add the --test option. For example:
scala-cli --power compile --test . When you want Scala-CLI to recompile your code on any changes, add the option --watch. For example:
scala-cli compile --watch . To create a test file, add test between the file name and the extension scala.
For example: MyFile.test.scala
To add dependencies to your tests, use directives with a test prefix on the dependency. For example:
//> using test.dep com.lihaoyi::utest:0.9.0Testing all the tests suites in the current directory and subdirectories:
scala-cli --power test .Testing a specific test suite:
scala-cli --power test <path_from_the_root>/MyFile.test.scalaScala CLI can format your code based on a default configuration of scalafmt that is set up by the Scala CLI team.
If you want to use a specific configuration, you have to add a .scalafmt.conf file in the root directory.
To format the code, run:
scala-cli fmt .If you want to include a format check in your CI/CD, use:
scala-cli fmt --check .Scala CLI will read all your scaladoc in the source code and generate a documentation webpage.
The scope of the generated documentation will be limited to the directory where you execute the following command:
scala-cli --power doc . -o scala-docAs a result, a directory scala-doc will be created. To see the documentation, just open /index.html inside the scala-doc directory.
To run your main class you can use:
scala-cli --power run D_IdValidator.scala .But since run is the default mode of Scala-CLI, the following is equivalent:
scala-cli --power D_IdValidator.scala .