Skip to main content

What is the difference between Scala runner and Scala CLI

Picture of Piotr Chabelski, Scala Engineer @ Scala CLI

Piotr Chabelski

Scala Engineer @ Scala CLI
Mar 22, 2023|40 min read
What_is_the_difference_between_Scala_runner_and_Scala_CLI_image-min.jpg
1object Hello extends App {
2 println("Hello world")
3}
1scala HelloWorld.scala
2# Hello world
1scala
2# Welcome to Scala 3.2.1 (17.0.5, Java OpenJDK 64-Bit Server VM).
3# Type in expressions for evaluation. Or try :help.
4#
5# scala>
1scala-cli -S 2.13
2# Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 17.0.5).
3# Type in expressions for evaluation. Or try :help.
4#
5# scala>
1Similarly, picking a Java version doesn’t require downloading and installing it separately. The tool handles that as well.
1scala-cli fmt .
1//> using scala "3.2.1"
2//> using lib "com.lihaoyi::os-lib:0.9.0
3println(os.pwd)
1scala-cli pwd.sc
2# Compiling project (Scala 3.2.1, JVM)
3# Compiled project (Scala 3.2.1, JVM)
4# ~/scala-cli-tests/demo
1//> using jvm "16"
2public class Main {
3 public static void main(String[] args) {
4 System.out.println(System.getProperty("java.version"));
5 }
6}
1scala-cli Main.java
2# Compiling project (Java)
3# Compiled project (Java)
4# 16.0.2
1scala-cli https://gist.github.com/Gedochao/9816a2d3ca2597a77dcf8a3d9bc398a2
2# Compiling project (Scala 3.2.1, JVM)
3# Compiled project (Scala 3.2.1, JVM)
4# Hello
1scala-cli https://gist.githubusercontent.com/Gedochao/9577c5c7b06cd655b80c5da93a2bf5d3/raw/4600ff9733678c2d36e864384c4cc45188459369/hello.sc
2# Compiling project (Scala 3.2.1, JVM)
3# Compiled project (Scala 3.2.1, JVM)
4# Hello
vscode-demo

TODO vscode-demo

1scala-cli package Main.scala -o hello --native-image
2./hello
3# Hello
1scala --power package Main.scala -o hello --native-image
2./hello
3# Hello
1scala config power true
1cs setup
2cs install scala-experimental
1brew install virtuslab/scala-experimental/scala

Subscribe to our newsletter and never miss an article