https://github.com/typelevel/scalac-options
A library for configuring scalac options
https://github.com/typelevel/scalac-options
Last synced: 18 days ago
JSON representation
A library for configuring scalac options
- Host: GitHub
- URL: https://github.com/typelevel/scalac-options
- Owner: typelevel
- License: apache-2.0
- Created: 2022-08-02T13:08:55.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2026-04-07T22:43:55.000Z (about 1 month ago)
- Last Synced: 2026-04-08T00:26:02.273Z (about 1 month ago)
- Language: Scala
- Size: 236 KB
- Stars: 48
- Watchers: 9
- Forks: 18
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Notice: NOTICE
Awesome Lists containing this project
README
# scalac-options
[](https://github.com/typelevel/scalac-options/actions/workflows/ci.yml)
[](https://opensource.org/licenses/Apache-2.0)
[](https://discord.gg/D7wY3aH7BQ)
[](https://search.maven.org/artifact/org.typelevel/scalac-options_3)
*scalac-options* is a library containing logic for configuring Scala compiler options according to the current Scala compiler version.
This logic was originally developed in the [sbt-tpolecat](https://github.com/typelevel/sbt-tpolecat) sbt plugin, and this library is intended to enable the reuse of that logic in other build tool plugins, for example [sbt-typelevel](https://github.com/typelevel/sbt-typelevel) and [mill-tpolecat](https://github.com/DavidGregory084/mill-tpolecat).
## Usage
This library is published for Scala 2.12.x, 2.13.x and 3.1.x:
```scala
// sbt
"org.typelevel" %% "scalac-options" % "0.1.8"
// mill
ivy"org.typelevel::scalac-options:0.1.8"
// Scala CLI
//> using dep org.typelevel::scalac-options:0.1.8
```
This library offers functions for filtering proposed Scala compiler options according to Scala version:
```scala
scalacOptions := ScalacOptions.tokensForVersion(
ScalaVersion.V3_1_0, // the Scala compiler major, minor, patch version
ScalacOptions.default // a curated default option set
) // returns a Seq[String] of Scala compiler options
ScalacOptions.optionsForVersion(
ScalaVersion.V3_1_0,
ScalacOptions.default
) // returns a Set[ScalacOption]
```
A shorthand for using the default option set is also provided:
```scala
scalacOptions := ScalacOptions.defaultTokensForVersion(
ScalaVersion.V3_1_0
) // returns a Seq[String] of Scala compiler options based on the default option set
ScalacOptions.defaultOptionsForVersion(
ScalaVersion.V3_1_0
) // returns a Set[ScalacOption] based on the default option set
```
The following are simple examples of use in sbt and Mill. Note that they are not complete project definitions.
### Modifying options: Fatal warnings example
A common requirement is use a modified version of the default settings. In this example, we are going to enable fatal warnings.
```scala
ScalacOptions.tokensForVersion(
ScalaVersion.V3_1_0,
ScalacOptions.default ++ ScalacOptions.fatalWarningOptions
)
```
### sbt example
Add the following dependency to an `sbt` file within the project directory, for instance `project/plugins`:
```scala
libraryDependencies += "org.typelevel" %% "scalac-options" % "0.1.8"
```
Alter your `build.sbt` file as follows:
```scala
// Types are not imported directly to avoid collisions with sbt's classes.
import org.typelevel.scalacoptions
val scala3Version = "3.3.6"
project
.settings(
scalaVersion := scala3Version,
scalacOptions ++= scalacoptions.ScalacOptions.defaultTokensForVersion(
scalacoptions.ScalaVersion.unsafeFromString(scala3Version)
)
)
```
### Mill example
If you are using mill 1.x:
```scala
//| mvnDeps: ["org.typelevel::scalac-options:0.1.8"]
import org.typelevel.scalacoptions.*
object example extends ScalaModule {
def scalaVersion = "3.3.6"
override def scalacOptions = Task {
super.scalacOptions() ++
ScalacOptions.defaultTokensForVersion(
ScalaVersion.unsafeFromString(scalaVersion())
)
}
}
```
If you are using mill 0.x:
```scala
import $ivy.`org.typelevel::scalac-options:0.1.8`, org.typelevel.scalacoptions._
object example extends ScalaModule {
def scalaVersion = "3.3.6"
override def scalacOptions = T {
super.scalacOptions() ++
ScalacOptions.defaultTokensForVersion(
ScalaVersion.unsafeFromString(scalaVersion())
)
}
}
```
## Conduct
Participants are expected to follow the [Scala Code of Conduct](https://www.scala-lang.org/conduct/) while discussing the project on GitHub and any other venues associated with the project. See the [organizational Code of Conduct](https://github.com/typelevel/.github/blob/main/CODE_OF_CONDUCT.md) for more details.
## License
All code in this repository is licensed under the Apache License, Version 2.0. See [LICENSE](./LICENSE).