2019-02-25 10:23:36 -08:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
2019-02-25 10:23:36 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka
|
|
|
|
|
|
|
|
|
|
import sbt._
|
2019-04-04 15:35:18 +02:00
|
|
|
import Keys.{ scalacOptions, _ }
|
2019-02-25 10:23:36 -08:00
|
|
|
import sbt.plugins.JvmPlugin
|
|
|
|
|
|
2020-05-27 12:50:53 +01:00
|
|
|
object AkkaDisciplinePlugin extends AutoPlugin {
|
2019-02-25 10:23:36 -08:00
|
|
|
|
|
|
|
|
override def trigger: PluginTrigger = allRequirements
|
2020-05-27 12:50:53 +01:00
|
|
|
override def requires: Plugins = JvmPlugin
|
2019-02-25 10:23:36 -08:00
|
|
|
override lazy val projectSettings = disciplineSettings
|
2019-03-26 14:41:29 +01:00
|
|
|
|
2020-02-14 15:19:10 +01:00
|
|
|
// allow toggling for pocs/exploration of ideas without discpline
|
|
|
|
|
val enabled = !sys.props.contains("akka.no.discipline")
|
|
|
|
|
|
2019-08-02 14:02:51 -07:00
|
|
|
// We allow warnings in docs to get the 'snippets' right
|
2020-08-04 13:47:38 +02:00
|
|
|
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",
|
2020-08-10 08:15:43 +02:00
|
|
|
"akka-protobuf-v3",
|
2020-08-04 13:47:38 +02:00
|
|
|
// 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?
|
2020-08-10 08:15:43 +02:00
|
|
|
"akka-cluster-sharding-typed",
|
2020-08-17 08:29:12 +01:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
|
|
|
|
"akka-persistence-typed",
|
2020-08-10 08:15:43 +02:00
|
|
|
"akka-docs")
|
2019-03-26 14:41:29 +01:00
|
|
|
|
2020-01-22 05:47:18 +01:00
|
|
|
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",
|
2020-05-28 08:35:27 +01:00
|
|
|
"akka-cluster-sharding-typed",
|
2020-01-22 05:47:18 +01:00
|
|
|
"akka-distributed-data",
|
2020-09-08 15:10:21 +02:00
|
|
|
"akka-docs",
|
2020-01-22 05:47:18 +01:00
|
|
|
"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",
|
2020-02-14 15:19:10 +01:00
|
|
|
"akka-testkit")
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2019-04-16 00:10:42 -07:00
|
|
|
lazy val silencerSettings = {
|
2020-08-24 09:44:03 +02:00
|
|
|
val silencerVersion = "1.7.1"
|
2020-12-09 15:20:13 +07:00
|
|
|
val libs = Seq(
|
|
|
|
|
compilerPlugin(("com.github.ghik" %% "silencer-plugin" % silencerVersion).cross(CrossVersion.patch)),
|
|
|
|
|
("com.github.ghik" %% "silencer-lib" % silencerVersion % Provided).cross(CrossVersion.patch))
|
|
|
|
|
Seq(libraryDependencies ++= (if (autoScalaLibrary.value) libs else Nil))
|
2019-04-16 00:10:42 -07:00
|
|
|
}
|
2019-04-04 15:35:18 +02:00
|
|
|
|
2019-02-25 10:23:36 -08:00
|
|
|
lazy val disciplineSettings =
|
2020-02-14 15:19:10 +01:00
|
|
|
if (enabled) {
|
|
|
|
|
silencerSettings ++ Seq(
|
2020-09-08 15:10:21 +02:00
|
|
|
Compile / scalacOptions ++= Seq("-Xfatal-warnings"),
|
2020-02-14 15:19:10 +01:00
|
|
|
Test / scalacOptions --= testUndicipline,
|
2020-08-04 13:47:38 +02:00
|
|
|
Compile / javacOptions ++= (
|
2020-08-05 13:12:29 +01:00
|
|
|
if (!nonFatalJavaWarningsFor(name.value)) Seq("-Werror", "-Xlint:deprecation", "-Xlint:unchecked")
|
|
|
|
|
else Seq.empty
|
|
|
|
|
),
|
2020-08-12 08:12:08 +01:00
|
|
|
Compile / javacOptions in doc := Seq("-Xdoclint:none"),
|
2020-02-14 15:19:10 +01:00
|
|
|
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
|
|
|
|
|
silencerSettings ++ Seq(Compile / scalacOptions += "-deprecation")
|
|
|
|
|
}
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2020-02-14 15:19:10 +01:00
|
|
|
val testUndicipline = Seq("-Ywarn-dead-code" // '???' used in compile only specs
|
2019-04-04 09:58:21 +01:00
|
|
|
)
|
|
|
|
|
|
2019-02-25 10:23:36 -08:00
|
|
|
/**
|
2019-04-04 15:35:18 +02:00
|
|
|
* Remain visibly filtered for future code quality work and removing.
|
|
|
|
|
*/
|
2020-01-22 05:47:18 +01:00
|
|
|
val undisciplineScalacOptions = Set("-Ywarn-numeric-widen")
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2019-03-01 13:39:08 +01:00
|
|
|
/** These options are desired, but some are excluded for the time being*/
|
2019-03-20 08:12:40 +00:00
|
|
|
val disciplineScalacOptions = Set(
|
2019-02-25 10:23:36 -08:00
|
|
|
"-Ywarn-numeric-widen",
|
2019-03-26 14:41:29 +01:00
|
|
|
"-Yno-adapted-args",
|
2019-03-19 08:12:51 +01:00
|
|
|
"-deprecation",
|
2019-03-01 13:39:08 +01:00
|
|
|
"-Xlint",
|
2019-02-25 10:23:36 -08:00
|
|
|
"-Ywarn-dead-code",
|
|
|
|
|
"-Ywarn-inaccessible",
|
|
|
|
|
"-Ywarn-infer-any",
|
|
|
|
|
"-Ywarn-nullary-override",
|
|
|
|
|
"-Ywarn-nullary-unit",
|
|
|
|
|
"-Ywarn-unused:_",
|
|
|
|
|
"-Ypartial-unification",
|
2019-04-04 15:35:18 +02:00
|
|
|
"-Ywarn-extra-implicit")
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2020-09-08 15:10:21 +02:00
|
|
|
/**
|
|
|
|
|
* We are a little less strict in docs
|
|
|
|
|
*/
|
|
|
|
|
val docs = Seq(
|
|
|
|
|
scalacOptions ++= Seq(
|
|
|
|
|
// In docs, 'unused' variables can be useful for naming and showing the type
|
|
|
|
|
"-P:silencer:globalFilters=is never used",
|
|
|
|
|
// Import statements are often duplicated across multiple snippets in one file
|
|
|
|
|
"-P:silencer:globalFilters=Unused import",
|
|
|
|
|
// We keep documentation for this old API around for a while:
|
|
|
|
|
"-P:silencer:globalFilters=in object Dns is deprecated",
|
|
|
|
|
"-P:silencer:globalFilters=in class Dns is deprecated",
|
|
|
|
|
// Because we sometimes wrap things in a class:
|
|
|
|
|
"-P:silencer:globalFilters=The outer reference in this type test cannot be checked at run time",
|
|
|
|
|
// Because we show some things that are deprecated in
|
|
|
|
|
// 2.13 but don't have a replacement that was in 2.12:
|
|
|
|
|
"-P:silencer:globalFilters=deprecated \\(since 2.13.0\\)"
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-02-25 10:23:36 -08:00
|
|
|
}
|