LinuxCommandLibrary

scalac

TLDR

Compile a Scala source file

$ scalac [Hello.scala]
copy
Compile multiple files to a specific directory
$ scalac -d [classes/] [*.scala]
copy
Compile with classpath dependencies
$ scalac -classpath [lib/*] [Source.scala]
copy
Compile with verbose output
$ scalac -verbose [Source.scala]
copy
Compile with additional warnings
$ scalac -Xlint [Source.scala]
copy
Treat warnings as errors
$ scalac -Werror [Source.scala]
copy
Show compiler version
$ scalac -version
copy

SYNOPSIS

scalac [options] [source files]

DESCRIPTION

scalac is the compiler for the Scala programming language. It reads Scala source files (.scala) and compiles them into Java bytecode class files that run on the JVM.
By default, class files are placed in the same directory as their source files. Use -d to specify an alternate output directory or JAR file. The compiler integrates with Java classes via the classpath mechanism.
Options are categorized by prefix: -W for warnings, -V for verbose output, -X for extended options, and -Y for private/experimental options.

PARAMETERS

-d directory|jar

Specify where to place generated class files
-classpath path
Specify where to find user class files (colon-separated on Unix)
-bootclasspath path
Override location of bootstrap class files
-sourcepath path
Specify where to find input source files
-verbose
Output messages about what the compiler is doing
-deprecation
Emit warning and location for usages of deprecated APIs
-unchecked
Enable additional warnings for type erasure
-Werror
Fail compilation if there are any warnings
-Xlint
Enable recommended additional warnings
-version
Print product version and exit
-help
Print synopsis of standard options

CAVEATS

The JAVAHOME environment variable must point to a valid JDK installation. JAVAOPTS can pass additional options to the underlying JVM. Scala 3 uses a different compiler with some incompatible options.

HISTORY

Scala was designed by Martin Odersky starting in 2001 at EPFL, with the first public release in 2004. The name stands for "scalable language." Scala 3 (Dotty) was released in 2021 with significant language improvements.

SEE ALSO

scala(1), javac(1), sbt(1), java(1)

Copied to clipboard