Let's connect
Let's connect

What is the difference between Scala runner and Scala CLI

Picture of Piotr Chabelski, Scala Engineer @ Scala CLI

Piotr Chabelski

Scala Engineer @ Scala CLI

40 minutes read

java

object Hello extends App {
    println("Hello world")
}

bash

scala HelloWorld.scala
# Hello world

bash

scala
# Welcome to Scala 3.2.1 (17.0.5, Java OpenJDK 64-Bit Server VM).
# Type in expressions for evaluation. Or try :help.
#
# scala> 

bash

scala-cli -S 2.13
# Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 17.0.5).
# Type in expressions for evaluation. Or try :help.
# 
# scala> 

bash

Similarly, picking a Java version doesn’t require downloading and installing it separately. The tool handles that as well.

bash

scala-cli fmt .

java

//> using scala "3.2.1"
//> using lib "com.lihaoyi::os-lib:0.9.0
println(os.pwd)

bash

scala-cli pwd.sc
# Compiling project (Scala 3.2.1, JVM)
# Compiled project (Scala 3.2.1, JVM)
# ~/scala-cli-tests/demo

java

//> using jvm "16"
public class Main { 
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.version")); 
    } 
}

bash

scala-cli Main.java
# Compiling project (Java)
# Compiled project (Java)
# 16.0.2

bash

scala-cli https://gist.github.com/Gedochao/9816a2d3ca2597a77dcf8a3d9bc398a2
# Compiling project (Scala 3.2.1, JVM)
# Compiled project (Scala 3.2.1, JVM)
# Hello

bash

scala-cli https://gist.githubusercontent.com/Gedochao/9577c5c7b06cd655b80c5da93a2bf5d3/raw/4600ff9733678c2d36e864384c4cc45188459369/hello.sc
# Compiling project (Scala 3.2.1, JVM)
# Compiled project (Scala 3.2.1, JVM)
# Hello
vscode-demo

TODO vscode-demo

bash

scala-cli package Main.scala -o hello --native-image
./hello
# Hello

bash

scala --power package Main.scala -o hello --native-image
./hello
# Hello

bash

scala config power true

bash

cs setup
cs install scala-experimental

bash

brew install virtuslab/scala-experimental/scala

Liked the article?

Share it with others!

explore more on

Take the first step to a sustained competitive edge for your business

Get your free consultation

VirtusLab's work has met the mark several times over, and their latest project is no exception. The team is efficient, hard-working, and trustworthy. Customers can expect a proactive team that drives results.

Stephen Rooke
Stephen RookeDirector of Software Development @ Extreme Reach

VirtusLab's engineers are truly Strapi extensions experts. Their knowledge and expertise in the area of Strapi plugins gave us the opportunity to lift our multi-brand CMS implementation to a different level.

facile logo
Leonardo PoddaEngineering Manager @ Facile.it

VirtusLab has been an incredible partner since the early development of Scala 3, essential to a mature and stable Scala 3 ecosystem.

Martin_Odersky
Martin OderskyHead of Programming Research Group @ EPFL

The VirtusLab team's in-depth knowledge, understanding, and experience of technology have been invaluable to us in developing our product. The team is professional and delivers on time – we greatly appreciated this efficiency when working with them.

Michael_Grant
Michael GrantDirector of Development @ Cyber Sec Company