Skip to content

Commit

Permalink
Default to different scalafmt versions depending on Java version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Jun 20, 2024
1 parent 9cac6ac commit c5b9f7c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ trait ScalaKernelApi extends Cross.Module[String] with AlmondModule with Depende
def propertyFilePath = "almond/almond.properties"
def propertyExtra = T {
Seq(
"default-scalafmt-version" -> Deps.scalafmtDynamic.dep.version,
"scala-version" -> crossScalaVersion
"default-scalafmt-version" -> Deps.scalafmtDynamic.dep.version,
"default-scalafmt-version-java-8" -> Versions.scalafmtJava8,
"scala-version" -> crossScalaVersion
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ object Properties {
lazy val ammoniteSparkVersion =
Option(props.getProperty("ammonite-spark-version")).getOrElse("[unknown]")
lazy val defaultScalafmtVersionOpt = Option(props.getProperty("default-scalafmt-version"))
lazy val defaultScalafmtVersionJava8Opt =
Option(props.getProperty("default-scalafmt-version-java-8"))

def defaultScalafmtVersion(javaVersion: String): Option[String] =
if (javaVersion.startsWith("1.")) defaultScalafmtVersionJava8Opt
else defaultScalafmtVersionOpt
def defaultScalafmtVersion(): Option[String] =
defaultScalafmtVersion(sys.props("java.version"))

lazy val actualScalaVersion = Option(props.getProperty("scala-version")).getOrElse("[unknown]")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Scalafmt(
queueEc: ExecutionContext,
logCtx: LoggerContext,
defaultDialect: String,
defaultVersion: String = almond.api.Properties.defaultScalafmtVersionOpt.getOrElse("2.7.5")
defaultVersion: String = almond.api.Properties.defaultScalafmtVersion().getOrElse("3.7.15")
) {

private val log = logCtx(getClass)
Expand Down
1 change: 1 addition & 0 deletions project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object Versions {
def coursier = "2.1.10"
def jsoniterScala = "2.13.5"
def scalafmt = "3.7.15"
def scalafmtJava8 = "3.7.15"
}

implicit class DepOps(private val dep: Dep) {
Expand Down

0 comments on commit c5b9f7c

Please sign in to comment.