pekko/project/AkkaDisciplinePlugin.scala
Andrea Peruffo da70e0ccd4
Scala 3 cross compatible akka-actor / akka-testkit / akka-actor-tests (#29956)
* Remove @switch when it doesn't take effect
* Use ActorRef.noSender
* Minor tweaks to SchedulerSpec
* Disambiguate TypedActor for Scala 3
* Bump ScalaTest to a version compatible with Scala 3
* Bump ScalaCheck
* Disambiguate Event in SupervisorHierarchySpec
* Scala 3 compatible EventBusSpec
* Prevent private unused variables to be erased by Scala 3
* Bump mockito
* Explicit actorRef2Scala import
* restore original .scalafix.conf
* Scala 3 compatible tailrec
* Reminder to re add switch annotation in case
* Move to nowarn instead of silencer
* Bump to Scala 2.12.13
* Cross compatible annotations
* fix docs generation
* adapt the build for Scala 3
* fix errors but bus
* remove more SerialVersion from trait
* scalacheck only from scalatest
* cross-compile akka-actor-tests
* restore cross-compilation
* early initializers workaround
* scalacheck switch
* cross compatible FSM.State class
* cross compatible LARS spec
* Change results to pass LineNumberSpec
* fix stackoverflow in AsyncDnsResolverIntegrationSpec
* FSM.State unapply
* fix Scala 2.13 mima
* SerialVersionRemover compiler plugin
* removed unused nowarns
2021-02-01 16:38:29 +01:00

162 lines
5.6 KiB
Scala

/*
* Copyright (C) 2019-2021 Lightbend Inc. <https://www.lightbend.com>
*/
package akka
import sbt._
import Keys.{ scalacOptions, _ }
import sbt.plugins.JvmPlugin
object AkkaDisciplinePlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements
override def requires: Plugins = JvmPlugin
override lazy val projectSettings = disciplineSettings
// allow toggling for pocs/exploration of ideas without discpline
val enabled = !sys.props.contains("akka.no.discipline")
// We allow warnings in docs to get the 'snippets' right
val nonFatalJavaWarningsFor = Set(
// for sun.misc.Unsafe and AbstractScheduler
"akka-actor",
// references to deprecated PARSER fields in generated message formats?
"akka-actor-typed-tests",
// references to deprecated PARSER fields in generated message formats?
"akka-cluster-typed",
// use of deprecated akka.protobuf.GeneratedMessage
"akka-protobuf",
"akka-protobuf-v3",
// references to deprecated PARSER fields in generated message formats?
"akka-remote",
// references to deprecated PARSER fields in generated message formats?
"akka-distributed-data",
// references to deprecated PARSER fields in generated message formats?
"akka-cluster-sharding-typed",
// references to deprecated PARSER fields in generated message formats?
"akka-persistence-typed",
"akka-docs")
val looseProjects = Set(
"akka-actor",
"akka-actor-testkit-typed",
"akka-actor-tests",
"akka-actor-typed",
"akka-actor-typed-tests",
"akka-bench-jmh",
"akka-cluster",
"akka-cluster-metrics",
"akka-cluster-sharding",
"akka-cluster-sharding-typed",
"akka-distributed-data",
"akka-docs",
"akka-persistence",
"akka-persistence-tck",
"akka-persistence-typed",
"akka-persistence-query",
"akka-remote",
"akka-remote-tests",
"akka-stream",
"akka-stream-testkit",
"akka-stream-tests",
"akka-stream-tests-tck",
"akka-testkit")
val defaultScalaOptions = "-Wconf:cat=unused-nowarn:s,any:e"
lazy val nowarnSettings = {
Dependencies.getScalaVersion() match {
case three if three.startsWith("3.0") =>
Seq(Compile / scalacOptions := Seq(), Compile / doc / scalacOptions := Seq())
case _ =>
Seq(
Compile / scalacOptions += defaultScalaOptions,
Test / scalacOptions += defaultScalaOptions,
Compile / doc / scalacOptions := Seq())
}
}
/**
* We are a little less strict in docs
*/
val docs = {
Dependencies.getScalaVersion() match {
case _ =>
Seq(
Compile / scalacOptions -= defaultScalaOptions,
Compile / scalacOptions += "-Wconf:cat=unused:s,cat=deprecation:s,cat=unchecked:s,any:e",
Test / scalacOptions --= Seq("-Xlint", "-unchecked", "-deprecation"),
Test / scalacOptions -= defaultScalaOptions,
Test / scalacOptions += "-Wconf:cat=unused:s,cat=deprecation:s,cat=unchecked:s,any:e",
Compile / doc / scalacOptions := Seq())
}
}
lazy val disciplineSettings =
if (enabled) {
nowarnSettings ++ Seq(
Compile / scalacOptions ++= Seq("-Xfatal-warnings"),
Test / scalacOptions --= testUndicipline,
Compile / javacOptions ++= (
if (Dependencies.getScalaVersion().startsWith("3.0")) {
Seq()
} else {
if (!nonFatalJavaWarningsFor(name.value)) Seq("-Werror", "-Xlint:deprecation", "-Xlint:unchecked")
else Seq.empty
}
),
Compile / javacOptions in doc := Seq("-Xdoclint:none"),
Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
disciplineScalacOptions -- Set(
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ypartial-unification",
"-Yno-adapted-args")
case Some((2, 12)) =>
disciplineScalacOptions
case _ =>
Nil
}).toSeq,
Compile / scalacOptions --=
(if (looseProjects.contains(name.value)) undisciplineScalacOptions.toSeq
else Seq.empty),
// Discipline is not needed for the docs compilation run (which uses
// different compiler phases from the regular run), and in particular
// '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 akka-actor/doc'
// https://github.com/akka/akka/issues/26119
Compile / doc / scalacOptions --= disciplineScalacOptions.toSeq :+ "-Xfatal-warnings",
// having discipline warnings in console is just an annoyance
Compile / console / scalacOptions --= disciplineScalacOptions.toSeq)
} else {
// we still need these in opt-out since the annotations are present
nowarnSettings ++ Seq(Compile / scalacOptions += "-deprecation")
}
val testUndicipline = Seq("-Ywarn-dead-code" // '???' used in compile only specs
)
/**
* Remain visibly filtered for future code quality work and removing.
*/
val undisciplineScalacOptions = Set("-Ywarn-numeric-widen")
/** These options are desired, but some are excluded for the time being*/
val disciplineScalacOptions = Set(
"-Ywarn-numeric-widen",
"-Yno-adapted-args",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-unused:_",
"-Ypartial-unification",
"-Ywarn-extra-implicit")
}