scalac(1)
β¨ NAME β¨
okay so bestie, this is the manual page for scalac β the compiler for the Scala 2 language. she lives under USER COMMANDS, and she is that girl. π
π¦ SYNOPSIS π¦
scalac [ <options> ] <source files>
πΈ PARAMETERS πΈ
<options>β command line options. peep OPTIONS below, bestie.<source files>β one or more source files to be compiled (such asMyClass.scala). yes, she can take multiple. π
π DESCRIPTION π
The scalac tool reads class and object definitions, written in the Scala programming language, and compiles them into bytecode class files. no cap, that's the whole job.
By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with -d (see OPTIONS, below). lowkey iconic.
π OPTIONS π
The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non-standard options are specific to the current virtual machine implementation and are subject to change in the future. Non-standard options begin with -X. periodt.
π Standard Options π
-Dproperty=valueβ Pass-Dproperty=valuedirectly to the runtime system.-J<flag>β Pass<flag>directly to the runtime system.-P:<plugin:opt>β Pass an option to a plugin.-Xβ Print a synopsis of advanced options.-bootclasspath <path>β Override location of bootstrap class files (where to find the standard built-in classes, such as"scala.List").-classpath <path>β Specify where to find user class files (on Unix-based systems a colon-separated list of paths, on Windows-based systems, a semicolon-separated list of paths). This does not override the built-in ("boot") search path.
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings. do not forget the dot, bestie, I am begging. π
-d <directory|jar>β Specify where to place generated class files.-deprecationβ Emit warning and location for usages of deprecated APIs.
Available since Scala version 2.2.1.
-encoding <encoding>β Specify character encoding used by source files.
The default value is platform-specific (Linux: "UTF8", Windows: "Cp1252"). Executing the following code in the Scala interpreter will return the default value on your system:
scala> new java.io.InputStreamReader(System.in).getEncoding
-explaintypesβ Explain type errors in more detail.-extdirs <dirs>β Override location of installed extensions.-featureβ Emit warning and location for usages of features that should be imported explicitly.-g:{none,source,line,vars,notailcalls}β controls debug info:"none"generates no debugging info,"source"generates only the source file attribute,"line"generates source and line number information,"vars"generates source, line number and local variable information,"notailcalls"generates all of the above and will not perform tail call optimization.
-helpβ Print a synopsis of standard options.-javabootclasspath <path>β Override Java boot classpath.-javaextdirs <path>β Override Java extdirs classpath.-language:<feature>β Enable one or more language features.-no-specializationβ Ignore@specializeannotations.-nobootcpβ Do not use the boot classpath for the Scala jar files.-nowarnβ Generate no warnings.-optimiseβ Generates faster bytecode by applying optimisations to the program.-printβ Print program with all Scala-specific features removed.-sourcepath <path>β Specify location(s) of source files.-target:{jvm-1.5,jvm-1.6,jvm-1.7,jvm-1.8}β choose target JVM:"jvm-1.5"target JVM 1.5 (deprecated),"jvm-1.6"target JVM 1.6 (default),"jvm-1.7"target JVM 1.7,"jvm-1.8"target JVM 1.8,
-toolcp <path>β Add to the runner classpath.-uncheckedβ Enable detailed unchecked (erasure) warnings.
Non variable type-arguments in type patterns are unchecked since they are eliminated by erasure.
Available since Scala version 2.3.0.
-uniqidβ Uniquely tag all identifiers in debugging output.-usejavacpβ Utilize thejava.class.pathin classpath resolution.-usemanifestcpβ Utilize the manifest in classpath resolution.-verboseβ Output messages about what the compiler is doing.-versionβ Print product version and exit.@<file>β A text file containing compiler arguments (options and source files).
π₯ Advanced Options π₯
-Xcheckinitβ Wrap field accessors to throw an exception on uninitialized access.-Xdevβ Enable warnings for developers working on the Scala compiler.-Xdisable-assertionsβ Generate no assertions and assumptions.-Xelide-below <n>β Calls to@elidablemethods are omitted if method priority is lower than argument.-Xexperimentalβ Enable experimental extensions.-Xfatal-warningsβ Fail the compilation if there are any warnings.-Xfull-lubsβ Retain pre2.10behavior of less aggressive truncation of least upper bounds.-Xfutureβ Turn on future language features.-Xgenerate-phase-graph <file>β Generate the phase graphs (outputs.dotfiles) tofileX.dot.-Xlintβ Enable recommended additional warnings.-Xlog-free-termsβ Print a message when reification creates a free term.-Xlog-free-typesβ Print a message when reification resorts to generating a free type.-Xlog-implicit-conversionsβ Print a message whenever an implicit conversion is inserted.-Xlog-implicitsβ Show more detail on why some implicits are not applicable.-Xlog-reflective-callsβ Print a message when a reflective method call is generated.-Xmacro-settings:<option>β Custom settings for macros.-Xmain-class <path>β Class for manifest'sMain-Classentry (only useful with-d <jar>).-Xmax-classfile-name <n>β Maximum filename length for generated classes.-Xmigration:<version>β Warn about constructs whose behavior may have changed since<version>.-Xno-forwardersβ Do not generate static forwarders in mirror classes.-Xno-patmat-analysisβ Don't perform exhaustivity/unreachability analysis. Also, ignore@switchannotation.-Xno-uescapeβ Disable handling of\uunicode escapes.-Xnojlineβ Do not use JLine for editing.-Xplugin:<paths>β Load a plugin from each classpath.-Xplugin-disable:<plugin>β Disable plugins by name.-Xplugin-listβ Print a synopsis of loaded plugins.-Xplugin-require:<plugin>β Abort if a named plugin is not loaded.-Xpluginsdir <path>β Path to search for plugin archives.-Xprint:<phases>β Print out program after<phases>(see below).-Xprint-icode[:<phases>]β Log internal icode to*.icodefiles after<phases>(default:icode).-Xprint-posβ Print tree positions, as offsets.-Xprint-typesβ Print tree types (debugging option).-Xpromptβ Display a prompt after each error (debugging option).-Xresidentβ Compiler stays resident, files to compile are read from standard input.-Xscript <object>β Treat the source file as a script and wrap it in a main method.-Xshow-class <class>β Show internal representation of class.-Xshow-object <object>β Show internal representation of object.-Xshow-phasesβ Print a synopsis of compiler phases.-Xsource:<version>β Treat compiler input as Scala source for the specified version, seeSI-8126.-Xsource-reader <classname>β Specify a custom method for reading source files.-Xstrict-inferenceβ Don't infer known-unsound types.-Xverifyβ Verify generic signatures in generated bytecode (asm backend only).-Xxml:{coalescing}β Configure XML parsing.
"coalescing" convert PCData to Text and coalesce sibling nodes (default in 2.11).
-Yβ Print a synopsis of private options.
π Compilation Phases π
parserβ parse source into ASTs, perform simple desugaring.namerβ resolve names, attach symbols to named trees.packageobjectsβ load package objects.typerβ the meat and potatoes: type the trees.patmatβ translate match expressions.superaccessorsβ add super accessors in traits and nested classes.extmethodsβ add extension methods for inline classes.picklerβ serialize symbol tables.refchecksβ reference/override checking, translate nested objects.selectiveanfβ ANF pre-transform for@cps(CPS plugin).selectivecpsβ@cps-driven transform of selectiveanf assignments (CPS plugin).uncurryβ uncurry, translate function values to anonymous classes.tailcallsβ replace tail calls by jumps.specializeβ@specialized-driven class and method specialization.explicitouterβ this refs to outer pointers, translate patterns.erasureβ erase types, add interfaces for traits.posterasureβ clean up erased inline classes.lazyvalsβ allocate bitmaps, translate lazy vals into lazified defs.lambdaliftβ move nested functions to top level.constructorsβ move field definitions into constructors.flattenβ eliminate inner classes.mixinβ mixin composition.cleanupβ platform-specific cleanups, generate reflective calls.delambdafyβ remove lambdas.icodeβ generate portable intermediate code.inlinerβ optimization: do inlining.inlineHandlersβ optimization: inline exception handlers.closelimβ optimization: eliminate uncalled closures.constoptβ optimization: optimize null and other constants.dceβ optimization: eliminate dead code.jvmβ generate JVM bytecode.terminalβ the last phase in the compiler chain.allβ matches all phases.
πΈ ENVIRONMENT πΈ
okay bestie, before we get into the environment vars, just know that these are the lil knobs and dials that control how scalac actually runs the JVM underneath. super important, lowkey underrated. let's go π
JAVACMDβ this one tells everything whichjavacommand to use when it runs your Scala code. and get this β you can put arguments right in there too! spaces, quotation marks, all of it? it just gets passed straight to the shell for expansion. so like, whatever you'd type in a shell, it'll figure out. slay. β¨JAVA_HOMEβ points at the JDK/JRE home directory. this is where it goes looking for thejavacommand... unless you already setJAVACMD, in which case that one wins. soJAVA_HOMEis the backup plan, the understudy, the girl who steps in when the main character isn't there. π«ΆJAVA_OPTSβ the options you wanna pass to thejavacommand thatJAVACMDpoints to. this is where you get to flex. for real, if you're on Java 1.5 or newer you can set up the JVM's memory usage like this:
JAVA_OPTS="-Xmx512M -Xms16M -Xss16M"
β¨ EXAMPLES β¨
bestie these are the receipts, the actual copy-paste-able goodness. go wild:
Compile a Scala program to the current directory
scalac HelloWorld
Compile a Scala program to the destination directory classes
scalac -d classes HelloWorld.scala
Compile a Scala program using a user-defined java command
env JAVACMD=/usr/local/bin/cacao scalac -d classes
HelloWorld.scala
Compile all Scala files found in the source directory src to the destination directory classes
scalac -d classes src/*.scala
notice that last one usessrc/*.scalaand not justsrc/β the shell's doing the globbing, notscalac, iykyk. π
π EXIT STATUS π
okay so here's the vibe check on how scalac tells you if it ate or not:
scalac returns a zero exit status if it succeeds to compile the specified input files. (yes, the original says "exist status," we're all just gonna hold hands and move past it π). and if it fails? non zero comes back at you. no in-between, no ambiguity, it's giving very decisive. π
π AUTHOR π
Written by Martin Odersky and other members of the Scala team. iconic behavior fr fr, the literal founding fathers of the language. we stan. π
π REPORTING BUGS π
found something cursed? Report bugs to https://issues.scala-lang.org/. do it, bestie, the maintainers wanna know. π«Ά
π COPYRIGHT π
This is open-source software, available to you under a BSD-like license. See accompanying "copyright" or "LICENSE" file for copying conditions.
and this part is serious so I'm saying it straight: There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. like, none. zero. not a crumb. π
π¦ SEE ALSO π¦
that's the whole page bestie, you made it to the end, main character energy only. this was version 1.0, dated March 2012, and it's the scalac(1) page β go forth and compile something gorgeous. periodt. πβ¨
π¦ where this page comes from
- debian bookworm: scala 2.11.12-5 Β· BSD-3-Clause
- debian trixie: scala 2.11.12-6 Β· BSD-3-Clause
- ubuntu jammy: scala 2.11.12-5 Β· BSD-3-Clause
- ubuntu noble: scala 2.11.12-5 Β· BSD-3-Clause
- ubuntu questing: scala 2.11.12-6
- ubuntu resolute: scala 2.11.12-6build1 Β· BSD-3-Clause
- ubuntu stonking: scala 2.11.12-6build1 Β· BSD-3-Clause
- (c) 2002-2013, LAMP/EPFL #
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms