diff --git a/src/main/scala/ScalaModulePlugin.scala b/src/main/scala/ScalaModulePlugin.scala index 441a82b..4945a7d 100644 --- a/src/main/scala/ScalaModulePlugin.scala +++ b/src/main/scala/ScalaModulePlugin.scala @@ -46,17 +46,26 @@ object ScalaModulePlugin extends AutoPlugin { ) /** - * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version. + * Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the Scala version. + * + * Note that the optimizer is only enabled in CI and not during local development. + * Thus, for consistent results, release artifacts must only be built on CI -- + * which is the expected norm for Scala modules, anyway. */ lazy val enableOptimizer: Setting[_] = Compile / compile / scalacOptions ++= { - val Ver = """(\d+)\.(\d+)\.(\d+).*""".r - val Ver(epic, maj, min) = scalaVersion.value - (epic, maj.toInt, min.toInt) match { - case ("2", m, _) if m < 12 => Seq("-optimize") - case ("2", 12, n) if n < 3 => Seq("-opt:l:project") - case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + scalaModuleEnableOptimizerInlineFrom.value) - case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html - } + if (insideCI.value) { + val log = sLog.value + val inlineFrom = scalaModuleEnableOptimizerInlineFrom.value + log.info(s"Running in CI, enabling Scala2 optimizer for module: ${name.value} with -opt-inline-from: $inlineFrom") + val Ver = """(\d+)\.(\d+)\.(\d+).*""".r + val Ver(epic, maj, min) = scalaVersion.value + (epic, maj.toInt, min.toInt) match { + case ("2", m, _) if m < 12 => Seq("-optimize") + case ("2", 12, n) if n < 3 => Seq("-opt:l:project") + case ("2", _, _) => Seq("-opt:l:inline", "-opt-inline-from:" + inlineFrom) + case ("3", _, _) => Nil // Optimizer not yet available for Scala3, see https://docs.scala-lang.org/overviews/compiler-options/optimizer.html + } + } else Nil } /**