sbt/project/NightlyPlugin.scala

29 lines
773 B
Scala
Raw Normal View History

2014-12-18 23:40:20 +01:00
import sbt._
import Keys._
import Dependencies._
object NightlyPlugin extends AutoPlugin {
override def trigger = allRequirements
override def requires = plugins.JvmPlugin
2017-03-29 15:43:38 +02:00
2014-12-18 23:40:20 +01:00
object autoImport {
2017-03-29 15:43:38 +02:00
val includeTestDependencies = settingKey[Boolean]("Doesn't declare test dependencies.")
2014-12-18 23:40:20 +01:00
2017-03-29 15:43:38 +02:00
def testDependencies = libraryDependencies ++= (
Add fully-fledged macro check for value inside if `.value` inside the if of a regular task is unsafe. The wrapping task will always execute the value, no matter what the if predicate yields. This commit adds the infrastructure to lint code for every sbt DSL macro. It also adds example of neg tests that check that the DSL checks are in place. The sbt checks yield error for this specific case because we may want to explore changing this behaviour in the future. The solutions to this are straightforward and explained in the error message, that looks like this: ``` EXPECTED: The evaluation of `fooNeg` happens always inside a regular task. PROBLEM: `fooNeg` is inside the if expression of a regular task. Regular tasks always evaluate task inside the bodies of if expressions. SOLUTION: 1. If you only want to evaluate it when the if predicate is true, use a dynamic task. 2. Otherwise, make the static evaluation explicit by evaluating `fooNeg` outside the if expression. ``` Aside from those solutions, this commit also adds a way to disable any DSL check by using the new `sbt.unchecked` annotation. This annotation, similar to `scala.annotation.unchecked` disables compiler output. In our case, it will disable any task dsl check, making it silent. Examples of positive checks have also been added. There have been only two places in `Defaults.scala` where this check has made compilation fail. The first one is inside `allDependencies`. To ensure that we still have static dependencies for `allDependencies`, I have hoisted up the value invocation outside the if expression. We may want to explore adding a dynamic task in the future, though. We are doing unnecessary work there. The second one is inside `update` and is not important because it's not exposed to the user. We use a `taskDyn`.
2017-05-25 10:54:51 +02:00
if (includeTestDependencies.value)
Seq(scalaCheck % Test, specs2 % Test, junit % Test, scalatest % Test)
2014-12-18 23:40:20 +01:00
else Seq()
2017-03-29 15:43:38 +02:00
)
2014-12-18 23:40:20 +01:00
}
2017-03-29 15:43:38 +02:00
import autoImport._
2014-12-18 23:40:20 +01:00
override def buildSettings: Seq[Setting[_]] = Seq(
includeTestDependencies := true
2014-12-18 23:40:20 +01:00
)
override def projectSettings: Seq[Setting[_]] = Seq(
crossVersion in update := CrossVersion.full,
2014-12-18 23:40:20 +01:00
resolvers += Resolver.typesafeIvyRepo("releases")
)
}