Skip to content

Latest commit

 

History

History
107 lines (86 loc) · 3.4 KB

File metadata and controls

107 lines (86 loc) · 3.4 KB

Scala-CLI mini guide

Install Scala-CLI

For macOS:

brew install Virtuslab/scala-cli/scala-cli

For Linux:

curl -sSLf https://scala-cli.virtuslab.org/get | sh

For Windows:

winget install virtuslab.scalacli

If 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.

IDE support for Scala-CLI

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:

  1. Compile
  2. Test
  3. Format
  4. Document
  5. Run

0. Experimental flag

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.

1. Compile

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 . 

2. Test

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.0

Testing 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.scala

3. Format

Scala 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 .

4. Document

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-doc

As a result, a directory scala-doc will be created. To see the documentation, just open /index.html inside the scala-doc directory.

5. Run

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 .