2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* license agreements; and to You under the Apache License, version 2.0:
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
2023-06-22 14:19:26 +01:00
|
|
|
* This file is part of the Apache Pekko project, which was derived from Akka.
|
2023-01-08 17:13:31 +08:00
|
|
|
*/
|
|
|
|
|
|
2019-02-25 10:23:36 -08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2019-2022 Lightbend Inc. <https://www.lightbend.com>
|
2019-02-25 10:23:36 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2022-12-02 14:49:16 +01:00
|
|
|
object PekkoDisciplinePlugin extends AutoPlugin {
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2024-01-22 07:15:16 +01:00
|
|
|
override lazy val trigger: PluginTrigger = allRequirements
|
|
|
|
|
override lazy val requires: Plugins = JvmPlugin
|
2019-02-25 10:23:36 -08:00
|
|
|
override lazy val projectSettings = disciplineSettings
|
2019-03-26 14:41:29 +01:00
|
|
|
|
2023-02-16 10:39:18 +01:00
|
|
|
// allow toggling for pocs/exploration of ideas without discipline
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val enabled = !sys.props.contains("pekko.no.discipline")
|
2020-02-14 15:19:10 +01:00
|
|
|
|
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
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-actor",
|
2020-08-04 13:47:38 +02:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-actor-typed-tests",
|
2020-08-04 13:47:38 +02:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-cluster-typed",
|
|
|
|
|
"pekko-protobuf-v3",
|
2020-08-04 13:47:38 +02:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-remote",
|
2020-08-04 13:47:38 +02:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-distributed-data",
|
2020-08-04 13:47:38 +02:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-cluster-sharding-typed",
|
2020-08-17 08:29:12 +01:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-persistence-typed",
|
2021-12-09 13:30:59 +01:00
|
|
|
// references to deprecated PARSER fields in generated message formats?
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-persistence-query",
|
|
|
|
|
"pekko-docs",
|
2023-04-05 13:44:58 +00:00
|
|
|
// references to deprecated Jackson methods that would involve a significant refactor to avoid
|
|
|
|
|
"pekko-serialization-jackson",
|
2022-04-20 20:40:45 +08:00
|
|
|
// use varargs of `Graph` in alsoTo and etc operators
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-stream-tests")
|
2019-03-26 14:41:29 +01:00
|
|
|
|
2020-01-22 05:47:18 +01:00
|
|
|
val looseProjects = Set(
|
2023-01-05 11:10:50 +01:00
|
|
|
"pekko-actor",
|
|
|
|
|
"pekko-actor-testkit-typed",
|
|
|
|
|
"pekko-actor-tests",
|
|
|
|
|
"pekko-actor-typed",
|
|
|
|
|
"pekko-actor-typed-tests",
|
|
|
|
|
"pekko-bench-jmh",
|
|
|
|
|
"pekko-cluster",
|
|
|
|
|
"pekko-cluster-metrics",
|
|
|
|
|
"pekko-cluster-sharding",
|
|
|
|
|
"pekko-cluster-sharding-typed",
|
|
|
|
|
"pekko-distributed-data",
|
|
|
|
|
"pekko-docs",
|
|
|
|
|
"pekko-persistence",
|
|
|
|
|
"pekko-persistence-tck",
|
|
|
|
|
"pekko-persistence-typed",
|
|
|
|
|
"pekko-persistence-query",
|
|
|
|
|
"pekko-remote",
|
|
|
|
|
"pekko-remote-tests",
|
|
|
|
|
"pekko-stream",
|
|
|
|
|
"pekko-stream-testkit",
|
|
|
|
|
"pekko-stream-tests",
|
|
|
|
|
"pekko-stream-tests-tck",
|
|
|
|
|
"pekko-testkit")
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2024-02-28 12:53:22 +08:00
|
|
|
lazy val defaultScalaOptions = Def.setting(CrossVersion.partialVersion(scalaVersion.value) match {
|
|
|
|
|
case Some((2, 12)) => "-Wconf:cat=unused-nowarn:s,any:e"
|
2024-05-04 15:20:47 +02:00
|
|
|
case _ => "-Wconf:cat=unused-nowarn:s,cat=other-shadowing:s,any:e"
|
2024-02-28 12:53:22 +08:00
|
|
|
})
|
2021-02-01 15:38:29 +00:00
|
|
|
|
2021-10-25 08:18:22 +02:00
|
|
|
lazy val nowarnSettings = Seq(
|
|
|
|
|
Compile / scalacOptions ++= (
|
|
|
|
|
if (scalaVersion.value.startsWith("3.")) Nil
|
2024-02-28 12:53:22 +08:00
|
|
|
else Seq(defaultScalaOptions.value)
|
2021-10-25 08:18:22 +02:00
|
|
|
),
|
|
|
|
|
Test / scalacOptions ++= (
|
|
|
|
|
if (scalaVersion.value.startsWith("3.")) Nil
|
2024-02-28 12:53:22 +08:00
|
|
|
else Seq(defaultScalaOptions.value)
|
2021-10-25 08:18:22 +02:00
|
|
|
),
|
|
|
|
|
Compile / doc / scalacOptions := Seq())
|
2021-02-01 15:38:29 +00:00
|
|
|
|
2023-07-03 18:57:55 +01:00
|
|
|
// ignore Scala compile warnings for Java 20+
|
|
|
|
|
lazy val jvmIgnoreWarnings = {
|
|
|
|
|
System.getProperty("java.version").startsWith("2")
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 15:38:29 +00:00
|
|
|
/**
|
|
|
|
|
* We are a little less strict in docs
|
|
|
|
|
*/
|
2024-01-22 07:15:16 +01:00
|
|
|
lazy val docs =
|
2021-10-25 08:18:22 +02:00
|
|
|
Seq(
|
2024-02-28 12:53:22 +08:00
|
|
|
Compile / scalacOptions -= defaultScalaOptions.value,
|
2021-12-23 11:33:21 +01:00
|
|
|
Compile / scalacOptions ++= (
|
|
|
|
|
if (scalaVersion.value.startsWith("3.")) Nil
|
|
|
|
|
else Seq("-Wconf:cat=unused:s,cat=deprecation:s,cat=unchecked:s,any:e")
|
|
|
|
|
),
|
2021-10-25 08:18:22 +02:00
|
|
|
Test / scalacOptions --= Seq("-Xlint", "-unchecked", "-deprecation"),
|
2024-02-28 12:53:22 +08:00
|
|
|
Test / scalacOptions -= defaultScalaOptions.value,
|
2021-12-23 11:33:21 +01:00
|
|
|
Test / scalacOptions ++= (
|
|
|
|
|
if (scalaVersion.value.startsWith("3.")) Nil
|
|
|
|
|
else Seq("-Wconf:cat=unused:s,cat=deprecation:s,cat=unchecked:s,any:e")
|
|
|
|
|
),
|
2021-10-25 08:18:22 +02:00
|
|
|
Compile / doc / scalacOptions := Seq())
|
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) {
|
2021-02-01 15:38:29 +00:00
|
|
|
nowarnSettings ++ Seq(
|
2020-09-08 15:10:21 +02:00
|
|
|
Compile / scalacOptions ++= Seq("-Xfatal-warnings"),
|
2021-11-12 17:30:49 +01:00
|
|
|
Test / scalacOptions --= testUndiscipline,
|
2020-08-04 13:47:38 +02:00
|
|
|
Compile / javacOptions ++= (
|
2023-07-03 18:57:55 +01:00
|
|
|
if (jvmIgnoreWarnings || scalaVersion.value.startsWith("3.") || nonFatalJavaWarningsFor(name.value)) {
|
|
|
|
|
Seq.empty
|
2021-02-01 15:38:29 +00:00
|
|
|
} else {
|
2023-07-03 18:57:55 +01:00
|
|
|
Seq("-Werror", "-Xlint:deprecation", "-Xlint:unchecked")
|
2021-02-01 15:38:29 +00:00
|
|
|
}
|
2020-08-05 13:12:29 +01:00
|
|
|
),
|
2021-05-25 12:50:51 +02:00
|
|
|
Compile / doc / javacOptions := 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",
|
2023-03-22 10:18:52 +01:00
|
|
|
"-Yno-adapted-args") ++ Set(
|
|
|
|
|
"-Xlint:-strict-unsealed-patmat")
|
2020-02-14 15:19:10 +01:00
|
|
|
case Some((2, 12)) =>
|
|
|
|
|
disciplineScalacOptions
|
|
|
|
|
case _ =>
|
2023-04-05 13:44:58 +00:00
|
|
|
Seq("-Wconf:cat=deprecation:s")
|
2020-02-14 15:19:10 +01:00
|
|
|
}).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
|
2023-02-16 10:39:18 +01:00
|
|
|
// '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 actor/doc'
|
2020-02-14 15:19:10 +01:00
|
|
|
// https://github.com/akka/akka/issues/26119
|
|
|
|
|
Compile / doc / scalacOptions --= disciplineScalacOptions.toSeq :+ "-Xfatal-warnings",
|
|
|
|
|
// having discipline warnings in console is just an annoyance
|
2021-11-17 01:00:05 +13:00
|
|
|
Compile / console / scalacOptions --= disciplineScalacOptions.toSeq,
|
|
|
|
|
Test / console / scalacOptions --= disciplineScalacOptions.toSeq)
|
2020-02-14 15:19:10 +01:00
|
|
|
} else {
|
|
|
|
|
// we still need these in opt-out since the annotations are present
|
2021-02-01 15:38:29 +00:00
|
|
|
nowarnSettings ++ Seq(Compile / scalacOptions += "-deprecation")
|
2020-02-14 15:19:10 +01:00
|
|
|
}
|
2019-02-25 10:23:36 -08:00
|
|
|
|
2021-11-12 17:30:49 +01:00
|
|
|
val testUndiscipline = 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",
|
2023-03-22 10:18:52 +01:00
|
|
|
"-Xlint",
|
2023-03-21 13:52:14 +01:00
|
|
|
"-Xlint:-infer-any",
|
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
|
|
|
|
|
|
|
|
}
|