scala-cli compile Hello.scala
# Compile with dependent classes
scala-cli compile Hello.scala Includes.scala
# Compiles all Scala files in the folder
scala-cli compile .# Compile and run `main` in Hello.scala
scala-cli run Hello.scala
# `run` command is the default and may be omitted for running the class
scala-cli Hello.scala
# Compile and run `main` with all associated files listed
scala-cli Hello.scala Utils.scala
# Compile the whole directory and run `main`
scala-cli .Running Scripts
Test.sc`
#!/usr/bin/env scala-cli
println("What a wonderful world!")scala-cli run HelloScript.scscala-cli compile Hello.scala --dependency org.typelevel::cats-core:2.6.1
scala-cli compile Hello.scala --jar /path/to/library.jarscala-cli --watch .
scala-cli --watch Hello.scala
scala-cli compile --watch Hello.scala
scala-cli compile --scala 2.13.6 Hello.scalaPicks the highest corresponding stable Scala version
scala-cli compile --scala 2.12 Hello.scala
scala-cli compile --scala 2 Hello.scala
scala-cli compile --scala 3 Hello.scalascala-cli compile Hello.scala -Xlint:unusedscala-cli compile \
--scala 2.13 \
--compiler-plugin com.olegpy:better-monadic-for:0.3.1 \
Hello.scalaIf there is more than one main found:
➜ scala-cli .
Compiling project (Scala 3.0.2, JVM)
Compiled project (Scala 3.0.2, JVM)
Found several main classes: Hello, Includes... in that case:
scala-cli --main-class Includes .
Compiling project (Scala 3.0.2, JVM)
Compiled project (Scala 3.0.2, JVM)
Includes says hi!scala-cli . --jvm graalvm:21Create a distributable library (eg. Maven)
scala-cli package --library Hello.scala -o hello.jar
javap -cp hello.jar hello.HelloCreate a light-weight executable/launcher JAR
scala-cli package Hello.scala -o helloCreate an heavy-weight executable assembly
scala-cli package --assembly Hello.scala -o helloCreate an executable and package into a docker image
scala-cli package --docker Hello.scala --docker-image-repository hello-dockerCreate a native executable
scala-cli package --native Hello.scala -o hello-native
scala-cli package --native -S 2.13 --main-class Hello . -o hello-native➜ scala-cli repl .
Compiling project (Scala 3.0.2, JVM)
Compiled project (Scala 3.0.2, JVM)
Warning: found classes defined in the root package (Hello, Hello$, Includes, Includes$, test, test$, test_sc, test_sc$). These will not be accessible from the REPL.
scala> Includes.run(Array.empty)
Includes says hi!
scala> Hello.main(Array.empty)
Scala says Hello! ** 2021-10-22T11:23:47.327515
scala> Includes.echo("1234567890")
You said: 1234567890There are some known limitation(s); hopefully for the time being.
scala-cli fmt
scala-cli fmt --check
scala-cli fmt --dialect scala212Removed all generated files (primarily those in .scala/)
scala-cli clean .