Convert to using slash syntax

This commit is contained in:
Eugene Yokota 2022-10-23 04:18:52 -04:00
parent ceb1ea8aad
commit b1818b446b
55 changed files with 330 additions and 335 deletions

View File

@ -3,7 +3,7 @@ sbtPlugin := true
val copyOutputDir = taskKey[Unit]("Copies the compiled classes to a root-level directory")
copyOutputDir := {
val cd = (classDirectory in Compile).value
val cd = (Compile / classDirectory).value
val to = baseDirectory.value / "out spaced"
IO.copyDirectory(cd, to)
}

View File

@ -1,9 +1,11 @@
import sbt.nio.file.Glob
Compile / sourceGenerators += Def.task {
val files = Seq(sourceManaged.value / "foo.txt", sourceManaged.value / "bar.txt")
files.foreach(IO.touch(_))
files
Compile / sourceGenerators += {
Def.task {
val files = Seq(sourceManaged.value / "foo.txt", sourceManaged.value / "bar.txt")
files.foreach(IO.touch(_))
files
}
}
cleanKeepGlobs += Glob(sourceManaged.value, "bar.txt")

View File

@ -1,4 +1,4 @@
import sbt.nio.file.Glob
cleanKeepGlobs in Compile +=
Glob((classDirectory in Compile in compile).value, "X.class")
Compile / cleanKeepGlobs +=
Glob((Compile / compile / classDirectory).value, "X.class")

View File

@ -6,9 +6,8 @@ libraryDependencies += "org.scala-sbt" % "sbt" % sbtVersion.value
lazy val expectErrorNotCrash = taskKey[Unit]("Ensures that sbt properly set types on Trees so that the compiler doesn't crash on a bad reference to .value, but gives a proper error instead.")
expectErrorNotCrash := {
val fail = (compileIncremental in Compile).failure.value
fail.directCause match {
case Some(x: xsbti.CompileFailed) => ()
case _ => sys.error("Compiler crashed instead of providing a compile-time-only exception.")
}
val fail = (Compile / compileIncremental).failure.value
fail.directCause match
case Some(x: xsbti.CompileFailed) => ()
case _ => sys.error("Compiler crashed instead of providing a compile-time-only exception.")
}

View File

@ -1,5 +1,5 @@
-> compile
> 'set sources in (Compile, compile) := { val src = (sources in (Compile, compile)).value; src.filterNot(_.getName contains "C") }'
> 'set Compile / compile / sources := { val src = (Compile / compile / sources).value; src.filterNot(_.getName contains "C") }'
> compile

View File

@ -3,15 +3,13 @@ lazy val foo = taskKey[Unit]("Runs the foo task")
lazy val bar = taskKey[Unit]("Runs the bar task")
def makeFoo(config: Configuration): Setting[_] =
foo in config := IO.write(file(s"${config.name}-foo"), "foo")
config / foo := IO.write(file(s"${config.name}-foo"), "foo")
lazy val PerformanceTest = (config("pt") extend Test)
lazy val root = (
(project in file("."))
lazy val root = (project in file("."))
.configs(PerformanceTest)
.settings(Seq(Compile, Test, Runtime, PerformanceTest).map(makeFoo) :_*)
.settings(
bar in PerformanceTest := IO.write(file("pt-bar"), "bar")
PerformanceTest / bar := IO.write(file("pt-bar"), "bar")
)
)

View File

@ -9,11 +9,11 @@ lazy val root = (project in file("."))
scalaVersion := "2.12.12",
Compile / doc / scalacOptions += "-Xfatal-warnings",
commands += Command.command("excludeB") { s =>
val impl = """val src = (sources in Compile).value; src.filterNot(_.getName.contains("B"))"""
s"set sources in (Compile, doc) := { $impl }" :: s
val impl = """val src = (Compile / sources).value; src.filterNot(_.getName.contains("B"))"""
s"set Compile / doc / sources := { $impl }" :: s
},
commands += Command.arb(_ => ("setDocExtension": Parser[String]) ~> " " ~> matched(any.*)) { (s, filter: String) =>
val impl = s"""val src = (sources in Compile).value; src.filter(_.getName.endsWith("$filter"))"""
s"set sources in (Compile, doc) := { $impl }" :: s
val impl = s"""val src = (Compile / sources).value; src.filter(_.getName.endsWith("$filter"))"""
s"set Compile / doc / sources := { $impl }" :: s
},
)

View File

@ -18,7 +18,7 @@ lazy val checkDifferentConfigClasses = taskKey[Unit]("Checks that the number of
configClassCountFile := (target.value / "config-count")
numConfigClasses := {
val cdir = (baseDirectory in ThisBuild).value / "project/target/config-classes"
val cdir = (ThisBuild / baseDirectory).value / "project/target/config-classes"
(cdir.allPaths --- cdir).get.length
}

View File

@ -2,31 +2,31 @@
ThisBuild / useCoursier := false
Seq(
autoAPIMappings in ThisBuild := true,
publishArtifact in (ThisBuild, packageDoc) := false,
publishArtifact in packageSrc := false,
organization in ThisBuild := "org.example",
version := "1.0"
ThisBuild / autoAPIMappings := true,
ThisBuild / packageDoc / publishArtifact := false,
packageSrc / publishArtifact := false,
ThisBuild / organization := "org.example",
version := "1.0",
)
val aPublishResolver = Def.setting {
Resolver.file("a-resolver", baseDirectory.in(ThisBuild).value / "a-repo")
Resolver.file("a-resolver", (ThisBuild / baseDirectory).value / "a-repo")
}
val aResolver = Def.setting {
val dir = baseDirectory.in(ThisBuild).value
"a-resolver" at s"file://${dir.getAbsolutePath}/a-repo"
val dir = (ThisBuild / baseDirectory).value
"a-resolver" at s"file://${dir.getAbsolutePath}/a-repo"
}
val bResolver = Def.setting {
val dir = baseDirectory.in(ThisBuild).value / "b-repo"
Resolver.file("b-resolver", dir)(Resolver.defaultIvyPatterns)
val dir = (ThisBuild / baseDirectory).value / "b-repo"
Resolver.file("b-resolver", dir)(Resolver.defaultIvyPatterns)
}
val apiBaseSetting = apiURL := Some(apiBase(name.value))
def apiBase(projectName: String) = url(s"http://example.org/${projectName}")
def scalaLibraryBase(v: String) = url(s"https://www.scala-lang.org/api/$v/")
def addDep(projectName: String) =
libraryDependencies += organization.value %% projectName % version.value
libraryDependencies += organization.value %% projectName % version.value
val checkApiMappings = taskKey[Unit]("Verifies that the API mappings are collected as expected.")
@ -34,44 +34,44 @@ val checkApiMappings = taskKey[Unit]("Verifies that the API mappings are collect
def expectedMappings = Def.task {
val version = scalaVersion.value
val binVersion = scalaBinaryVersion.value
val ms = update.value.configuration(Compile).get.modules.flatMap { mod =>
mod.artifacts.flatMap { case (a,f) =>
val n = a.name.stripSuffix("_" + binVersion)
n match {
case "a" | "b" | "c" => (f, apiBase(n)) :: Nil
case "scala-library" => (f, scalaLibraryBase(version)) :: Nil
case _ => Nil
}
}
}
val mc = (classDirectory in (c,Compile)).value -> apiBase("c")
(mc +: ms).toMap
val ms = update.value.configuration(Compile).get.modules.flatMap { mod =>
mod.artifacts.flatMap { case (a,f) =>
val n = a.name.stripSuffix("_" + binVersion)
n match {
case "a" | "b" | "c" => (f, apiBase(n)) :: Nil
case "scala-library" => (f, scalaLibraryBase(version)) :: Nil
case _ => Nil
}
}
}
val mc = (Compile / c / classDirectory).value -> apiBase("c")
(mc +: ms).toMap
}
val a = project.settings(
apiBaseSetting,
publishMavenStyle := true,
publishTo := Some(aPublishResolver.value)
apiBaseSetting,
publishMavenStyle := true,
publishTo := Some(aPublishResolver.value)
)
val b = project.settings(
apiBaseSetting,
publishMavenStyle := false,
publishTo := Some(bResolver.value)
apiBaseSetting,
publishMavenStyle := false,
publishTo := Some(bResolver.value)
)
val c = project.settings(apiBaseSetting)
val d = project.dependsOn( c ).settings(
externalResolvers := Seq(aResolver.value, bResolver.value),
addDep("a"),
addDep("b"),
checkApiMappings := {
val actual = apiMappings.in(Compile,doc).value
println("Actual API Mappings: " + actual.mkString("\n\t", "\n\t", ""))
val expected = expectedMappings.value
println("Expected API Mappings: " + expected.mkString("\n\t", "\n\t", ""))
assert(actual == expected)
}
externalResolvers := Seq(aResolver.value, bResolver.value),
addDep("a"),
addDep("b"),
checkApiMappings := {
val actual = (Compile / doc / apiMappings).value
println("Actual API Mappings: " + actual.mkString("\n\t", "\n\t", ""))
val expected = expectedMappings.value
println("Expected API Mappings: " + expected.mkString("\n\t", "\n\t", ""))
assert(actual == expected)
}
)

View File

@ -9,6 +9,6 @@ lazy val root = (project in file("."))
IO.write(file, "object BuildInfo")
file :: Nil
},
sourceGenerators in Compile += buildInfo,
sourceGenerators in Compile += Def.task { Nil }
Compile / sourceGenerators += buildInfo,
Compile / sourceGenerators += Def.task { Nil },
)

View File

@ -10,7 +10,7 @@ lazy val root = (project in file(".")).
name := "run-test",
runFoo := Def.inputTaskDyn {
val args = Def.spaceDelimited().parsed
(runMain in Compile).toTask(s" Foo " + args.mkString(" "))
(Compile / runMain).toTask(s" Foo " + args.mkString(" "))
}.evaluated,
check := {
val x = runFoo.toTask(" hi ho").value

View File

@ -12,9 +12,9 @@ lazy val root = (project in file(".")).
settings(
name := "run-test",
run2 := {
val one = (run in Compile).evaluated
val one = (Compile / run).evaluated
val sep = separator.parsed
val two = (run in Compile).evaluated
val two = (Compile / run).evaluated
},
check := {
val x = run2.toTask(" a b -- c d").value

View File

@ -3,18 +3,18 @@ lazy val intTask = taskKey[Int]("int")
lazy val root = (project in file(".")).
dependsOn(b, c).
settings(
intTask in Compile := {
Compile / intTask := {
// a sequence of tasks could be joined together
Seq(b, c).map(p => intTask in (p, Compile)).join.map( as => (1 /: as)(_ + _) ).value
Seq(b, c).map(p => Cmpile / p / intTask).join.map( as => (1 /: as)(_ + _) ).value
}
)
lazy val b = (project in file("b")).
settings(
intTask in Compile := 1
Compile / intTask := 1
)
lazy val c = (project in file("c")).
settings{
intTask in Compile := 2
Compile / intTask := 2
}

View File

@ -59,15 +59,15 @@ lazy val b = project
lazy val c = project.settings(
taskX := cGlobal,
taskX in Compile := cCompile,
taskX in Test := cTest
Compile / taskX := cCompile,
Test / taskX := cTest
)
lazy val d = project.settings(
taskX := dGlobal,
taskX in (Compile,console) := dConsole,
Compile / console / taskX := dConsole,
// these shouldn't get picked up
taskX in (Compile,compile) := Set(32366),
taskX in compile := Set(548686),
taskX in Configurations.IntegrationTest := Set(11111)
)
Compile / compile / taskX := Set(32366),
compile / taskX := Set(548686),
Configurations.IntegrationTest / taskX := Set(11111),
)

View File

@ -9,39 +9,38 @@ lazy val subB = project
x := 3
x in Compile in y := 7
Compile / y / x := 7
x in Runtime in y := 13
Runtime / y / x := 13
x in subA in Compile := {
val xcy = (x in Compile in y).previous getOrElse 0 // 7
// verify that This is properly resolved to Global and not the defining key's scope
val xg = x.previous getOrElse 0 // 3
println(s"xcy=$xcy, xg=$xg")
xcy * xg
subA / Compile / x := {
val xcy = (Compile / y / x).previous getOrElse 0 // 7
// verify that This is properly resolved to Global and not the defining key's scope
val xg = x.previous getOrElse 0 // 3
println(s"xcy=$xcy, xg=$xg")
xcy * xg
}
inConfig(Compile)(Seq(
y in subB := {
// verify that the referenced key gets delegated
val xty = (x in Test in y).previous getOrElse 0 // 13
// verify that inConfig gets applied
val xcy = (x in y).previous getOrElse 0 // 7
println(s"xcy=$xcy, xty=$xty")
xty * xcy
}
subB / y := {
// verify that the referenced key gets delegated
val xty = (Test / y / x).previous getOrElse 0 // 13
// verify that inConfig gets applied
val xcy = (y / x).previous getOrElse 0 // 7
println(s"xcy=$xcy, xty=$xty")
xty * xcy
}
))
def parser = {
import complete.DefaultParsers._
(Space ~> IntBasic) ~ (Space ~> IntBasic)
import complete.DefaultParsers._
(Space ~> IntBasic) ~ (Space ~> IntBasic)
}
checkScopes := {
val (expectedX, expectedY) = parser.parsed
val actualX = (x in subA in Compile).value
val actualY = (y in subB in Test).value
assert(actualX == expectedX, s"Expected 'x' to be $expectedX, got $actualX")
assert(actualY == expectedY, s"Expected 'y' to be $expectedY, got $actualY")
val (expectedX, expectedY) = parser.parsed
val actualX = (subA/ Compile / x).value
val actualY = (subB / Test / y).value
assert(actualX == expectedX, s"Expected 'x' to be $expectedX, got $actualX")
assert(actualY == expectedY, s"Expected 'y' to be $expectedY, got $actualY")
}

View File

@ -42,7 +42,7 @@ lazy val root = (project in file("."))
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
val previousAnalysis = (Compile / previousCompile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
@ -53,7 +53,7 @@ lazy val root = (project in file("."))
},
checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
val actual: Int = ((Compile / compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual")
}
)

View File

@ -1,7 +1,7 @@
val demo = taskKey[Unit]("Demo run task")
fullRunTask(demo, Compile, "A", "1", "1")
fork in demo := true
javaOptions in demo := "-Dsbt.check.forked=true" :: Nil
demo / fork := true
demo / javaOptions := "-Dsbt.check.forked=true" :: Nil
val demoIn = InputKey[Unit]("demoIn", "Demo run input task", demo)
fullRunInputTask(demoIn, Compile, "A", "1")

View File

@ -44,11 +44,11 @@ def testInputTask[T](name: String, expected: String, task: InputKey[T], arg: Str
myInputTask := argFunction(_.toUpperCase(Locale.ENGLISH)).evaluated
testInputTask("testRunInputTaskRoot", "FOO", myInputTask, "foo")
myInputTask in Compile := argFunction(_.toLowerCase(Locale.ENGLISH)).evaluated
Compile / myInputTask := argFunction(_.toLowerCase(Locale.ENGLISH)).evaluated
testInputTask("testRunInputTaskRootCompile", "foo", myInputTask in Compile, "FOO")
myInputTask in sub := argFunction(_.head.toString).evaluated
sub / myInputTask := argFunction(_.head.toString).evaluated
testInputTask("testRunInputTaskSub", "f", myInputTask in sub, "foo")
myInputTask in (sub, Compile) := argFunction(_.tail).evaluated
sub / Compile / myInputTask := argFunction(_.tail).evaluated
testInputTask("testRunInputTaskSubCompile", "oo", myInputTask in (sub, Compile), "foo")

View File

@ -5,9 +5,9 @@ logLevel := Level.Debug
incOptions ~= { _.withApiDebug(true) }
TaskKey[Unit]("show-apis") := {
val a = (compile in Compile).value match { case a: Analysis => a }
val scalaSrc = (scalaSource in Compile).value
val javaSrc = (javaSource in Compile).value
val a = (Compile / compile).value match { case a: Analysis => a }
val scalaSrc = (Compile / scalaSource).value
val javaSrc = (Compile / javaSource).value
val aApi = a.apis.internalAPI("test.A").api.classApi
val jApi = a.apis.internalAPI("test.J").api.classApi
import xsbt.api.DefaultShowAPI

View File

@ -6,7 +6,7 @@ val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
val previousAnalysis = (Compile / previousCompile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
@ -20,6 +20,6 @@ val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterati
checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
val actual: Int = ((Compile / compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual")
}

View File

@ -1,8 +1,8 @@
import sbt.internal.inc.Analysis
TaskKey[Unit]("verify-binary-deps") := {
val a = (compile in Compile).value match { case a: Analysis => a }
val classDir = (classDirectory in Compile).value
val a = (Compile / compile).value match { case a: Analysis => a }
val classDir = (Compile / classDirectory).value
val base = baseDirectory.value
val nestedPkgClass = classDir / "test/nested.class"
val fooSrc = base / "src/main/scala/test/nested/Foo.scala"

View File

@ -8,7 +8,7 @@ val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
val previousAnalysis = (Compile / previousCompile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
@ -22,6 +22,6 @@ val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterati
checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
val actual: Int = ((Compile / compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual")
}

View File

@ -6,7 +6,7 @@ val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
recordPreviousIterations := {
val log = streams.value.log
CompileState.previousIterations = {
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
val previousAnalysis = (Compile / previousCompile).value.analysis.asScala
previousAnalysis match {
case None =>
log.info("No previous analysis detected")
@ -20,6 +20,6 @@ val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterati
checkIterations := {
val expected: Int = (Space ~> NatBasic).parsed
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
val actual: Int = ((Compile / compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
assert(expected == actual, s"Expected $expected compilations, got $actual")
}

View File

@ -19,15 +19,15 @@ lazy val root = (project in file("."))
inConfig(Macro)(Defaults.configSettings),
// puts the compiled macro on the classpath for the main sources
unmanagedClasspath in Compile ++=
(fullClasspath in Macro).value,
Compile / unmanagedClasspath ++=
(Macro / fullClasspath).value,
// includes sources in src/macro/ in the main source package
mappings in (Compile, packageSrc) ++=
(mappings in (Macro, packageSrc)).value,
Compile / packageSrc / mappings ++=
(Macro / packageSrc / mappings).value,
// Includes classes compiled from src/macro/ in the main binary
// This can be omitted if the classes in src/macro/ aren't used at runtime
mappings in (Compile, packageBin) ++=
(mappings in (Macro, packageBin)).value
Compile / packageBin / mappings ++=
(Macro / packageBin / mappings).value
)

View File

@ -1,6 +1,6 @@
TaskKey[Unit]("checkJavaFailures") := {
val reporter = savedReporter.value
val ignore = (compile in Compile).failure.value
val ignore = (Compile / compile).failure.value
val ps = reporter.problems
assert(!ps.isEmpty, "Failed to report any problems!")
// First error should be on a specific line/file
@ -13,7 +13,7 @@ TaskKey[Unit]("checkJavaFailures") := {
TaskKey[Unit]("checkScalaFailures") := {
val reporter = savedReporter.value
val ignore = (compile in Compile).failure.value
val ignore = (Compile / compile).failure.value
val ps = reporter.problems
assert(!ps.isEmpty, "Failed to report any problems!")
// First error should be on a specific line/file

View File

@ -14,7 +14,7 @@ object TestPlugin extends AutoPlugin {
import autoImport._
override def projectSettings = Seq(
savedReporter := new CollectingReporter,
compilerReporter in (Compile, compile) := savedReporter.value,
Compile / compile / compilerReporter := savedReporter.value,
problems := savedReporter.value.problems
)
}

View File

@ -9,7 +9,7 @@ lazy val root = (project in file("."))
incOptions := incOptions.value.withClassfileManagerType(
Option(xsbti.compile.TransactionalManagerType.of(
crossTarget.value / "classes.bak",
(streams in (Compile, compile)).value.log
(Compile / compile / streams).value.log
): xsbti.compile.ClassFileManagerType).asJava
)
)

View File

@ -9,11 +9,11 @@ crossPaths := false
mainClass := Some("jartest.Main")
packageOptions in (Compile, packageBin) := {
Compile / packageBin / packageOptions := {
def manifestExtra = {
val mf = new Manifest
mf.getMainAttributes.put(Attributes.Name.CLASS_PATH, makeString(scalaInstance.value.libraryJars))
mf
}
(packageOptions in (Compile, packageBin)).value :+ Package.JarManifest(manifestExtra)
(Compile / packageBin / packageOptions).value :+ Package.JarManifest(manifestExtra)
}

View File

@ -2,7 +2,7 @@ name := "Mappings Test"
version := "0.2"
mappings in (Compile, packageBin) ++= {
Compile / packageBin / mappings ++= {
val test = file("test")
Seq(
test -> "test1",
@ -13,5 +13,5 @@ mappings in (Compile, packageBin) ++= {
lazy val unzipPackage = taskKey[Unit]("extract jar file")
unzipPackage := {
IO.unzip((packageBin in Compile).value, target.value / "extracted")
}
IO.unzip((Compile / packageBin).value, target.value / "extracted")
}

View File

@ -1,10 +1,6 @@
package jartest
object Main
{
def main(args: Array[String])
{
if(getClass.getResource("main_resource_test") == null)
System.exit(1)
}
}
object Main:
def main(args: Array[String]): Unit =
if(getClass.getResource("main_resource_test") == null)
System.exit(1)

View File

@ -22,8 +22,8 @@ package name.example {
import autoImport._
override def projectSettings = Seq[Setting[_]](
checkMaxErrors := (Keys.maxErrors map { me => assert(me == xyz, "Expected maxErrors to be " + xyz + ", but it was " + me ) }).value,
checkName := (Keys.name map { n => assert(n == "Demo", "Expected name to be 'Demo', but it was '" + n + "'" ) }).value
checkMaxErrors := (Keys.maxErrors mapN { me => assert(me == xyz, "Expected maxErrors to be " + xyz + ", but it was " + me ) }).value,
checkName := (Keys.name mapN { n => assert(n == "Demo", "Expected name to be 'Demo', but it was '" + n + "'" ) }).value
)
}
}

View File

@ -1,5 +1,5 @@
val test123 = project in file(".") enablePlugins TestP settings(
resourceGenerators in Compile += Def.task {
Compile / resourceGenerators += Def.task {
streams.value.log info "resource generated in settings"
Nil
}

View File

@ -2,7 +2,7 @@ import sbt._, Keys._
object TestP extends AutoPlugin {
override def projectSettings: Seq[Setting[_]] = Seq(
resourceGenerators in Compile += Def.task {
Compile / resourceGenerators += Def.task {
streams.value.log info "resource generated in plugin"
Nil
}

View File

@ -29,44 +29,44 @@ lazy val projI = project.enablePlugins(TopC)
lazy val disableAutoNoRequirePlugin = project.disablePlugins(OrgPlugin)
check := {
// Ensure organization on root is overridable.
val rorg = (organization).value // Should be None
same(rorg, "override", "organization")
// this will pass when the raw disablePlugin works.
val dversion = (projectID in projD).?.value // Should be None
same(dversion, None, "projectID in projD")
// Ensure organization on root is overridable.
val rorg = (organization).value // Should be None
same(rorg, "override", "organization")
// this will pass when the raw disablePlugin works.
val dversion = (projD / projectID).?.value // Should be None
same(dversion, None, "projectID in projD")
// Ensure with multiple .sbt files that disabling/enabling works across them
val fDel = (del in Quux in projF).?.value
same(fDel, Some(" Q"), "del in Quux in projF")
//
val adel = (del in projA).?.value // should be None
same(adel, None, "del in projA")
val bdel = (del in projB).?.value // should be None
same(bdel, None, "del in projB")
val ddel = (del in projD).?.value // should be None
same(ddel, None, "del in projD")
//
val buildValue = (demo in ThisBuild).value
same(buildValue, "build 0", "demo in ThisBuild")
val globalValue = (demo in Global).value
same(globalValue, "global 0", "demo in Global")
val projValue = (demo in projC).?.value
same(projValue, Some("project projC Q R"), "demo in projC")
val qValue = (del in projC in Quux).?.value
same(qValue, Some(" Q R"), "del in projC in Quux")
val optInValue = (del in projE in Quux).value
same(optInValue, " Q S R", "del in projE in Quux")
val overrideOrgValue = (organization in projE).value
same(overrideOrgValue, "S", "organization in projE")
// tests for top level plugins
val topLevelAValueG = (topLevelDemo in projG).value
// Ensure with multiple .sbt files that disabling/enabling works across them
val fDel = (projF / Quux / del).?.value
same(fDel, Some(" Q"), "del in Quux in projF")
//
val adel = (projA / del).?.value // should be None
same(adel, None, "del in projA")
val bdel = (projB / del).?.value // should be None
same(bdel, None, "del in projB")
val ddel = (projD / del).?.value // should be None
same(ddel, None, "del in projD")
//
val buildValue = (ThisBuild / demo).value
same(buildValue, "build 0", "demo in ThisBuild")
val globalValue = (Global / demo).value
same(globalValue, "global 0", "demo in Global")
val projValue = (projC / demo).?.value
same(projValue, Some("project projC Q R"), "demo in projC")
val qValue = (Quux / del in projC)(projC / del).?.value
same(qValue, Some(" Q R"), "del in projC in Quux")
val optInValue = (Quux / del in projE)(projE / del).value
same(optInValue, " Q S R", "del in projE in Quux")
val overrideOrgValue = (projE / organization).value
same(overrideOrgValue, "S", "organization in projE")
// tests for top level plugins
val topLevelAValueG = (projG / topLevelDemo).value
same(topLevelAValueG, "TopA: topLevelDemo project projG", "topLevelDemo in projG")
val demoValueG = (demo in projG).value
val demoValueG = (projG / demo).value
same(demoValueG, "TopA: demo project projG", "demo in projG")
val topLevelBValueH = (topLevelDemo in projH).value
val topLevelBValueH = (projH / topLevelDemo).value
same(topLevelBValueH, "TopB: topLevelDemo project projH", "topLevelDemo in projH")
val hdel = (del in projH).?.value
val hdel = (projH / del).?.value
same(hdel, None, "del in projH")
}
@ -75,5 +75,5 @@ keyTest := "foo"
topLevelKeyTest := "bar"
def same[T](actual: T, expected: T, label: String): Unit = {
assert(actual == expected, s"Expected '$expected' for `$label`, got '$actual'")
assert(actual == expected, s"Expected '$expected' for `$label`, got '$actual'")
}

View File

@ -1,97 +1,92 @@
package sbttest // you need package https://stackoverflow.com/questions/9822008/
import sbt._, Keys._
import java.util.concurrent.atomic.{AtomicInteger => AInt}
import sbt._, Keys._
import java.util.concurrent.atomic.{AtomicInteger => AInt}
object A extends AutoPlugin { override def requires: Plugins = empty }
object B extends AutoPlugin { override def requires: Plugins = empty }
object E extends AutoPlugin { override def requires: Plugins = empty }
object A extends AutoPlugin { override def requires: Plugins = empty }
object B extends AutoPlugin { override def requires: Plugins = empty }
object E extends AutoPlugin { override def requires: Plugins = empty }
object Imports
{
lazy val Quux = config("q")
lazy val Pippy = config("p").extend(Quux)
object Imports {
lazy val Quux = config("q")
lazy val Pippy = config("p").extend(Quux)
lazy val demo = settingKey[String]("A demo setting.")
lazy val del = settingKey[String]("Another demo setting.")
lazy val demo = settingKey[String]("A demo setting.")
lazy val del = settingKey[String]("Another demo setting.")
lazy val check = taskKey[Unit]("Verifies settings are as they should be.")
lazy val check = taskKey[Unit]("Verifies settings are as they should be.")
}
object OrgPlugin extends AutoPlugin {
override def trigger = allRequirements
override def requires: Plugins = empty
override def projectSettings = Seq(
object OrgPlugin extends AutoPlugin:
override def trigger = allRequirements
override def requires: Plugins = empty
override def projectSettings = Seq(
organization := "override"
)
}
)
object X extends AutoPlugin {
val autoImport = Imports
val autoImport = Imports
}
import Imports._
import Imports._
object D extends AutoPlugin {
override def requires: Plugins = E
override def trigger = allRequirements
override def requires: Plugins = E
override def trigger = allRequirements
object autoImport {
lazy val keyTest = settingKey[String]("Another demo setting.")
}
object autoImport {
lazy val keyTest = settingKey[String]("Another demo setting.")
}
}
object Q extends AutoPlugin
{
override def requires: Plugins = A && B
override def trigger = allRequirements
object Q extends AutoPlugin {
override def requires: Plugins = A && B
override def trigger = allRequirements
override def projectConfigurations: Seq[Configuration] =
Pippy ::
Quux ::
Nil
override def projectConfigurations: Seq[Configuration] =
Pippy ::
Quux ::
Nil
override def projectSettings: Seq[Setting[_]] =
(demo := s"project ${name.value}") ::
(del in Quux := " Q") ::
Nil
(demo := s"project ${name.value}") ::
(Quux / del := " Q") ::
Nil
override def buildSettings: Seq[Setting[_]] =
(demo := s"build ${buildCount.getAndIncrement}") ::
Nil
(demo := s"build ${buildCount.getAndIncrement}") ::
Nil
override def globalSettings: Seq[Setting[_]] =
(demo := s"global ${globalCount.getAndIncrement}") ::
Nil
(demo := s"global ${globalCount.getAndIncrement}") ::
Nil
// used to ensure the build-level and global settings are only added once
private[this] val buildCount = new AInt(0)
private[this] val globalCount = new AInt(0)
// used to ensure the build-level and global settings are only added once
private[this] val buildCount = new AInt(0)
private[this] val globalCount = new AInt(0)
}
object R extends AutoPlugin
{
// NOTE - Only plugins themselves support exclusions...
override def requires = Q
override def trigger = allRequirements
object R extends AutoPlugin {
// NOTE - Only plugins themselves support exclusions...
override def requires = Q
override def trigger = allRequirements
override def projectSettings = Seq(
// tests proper ordering: R requires Q, so Q settings should come first
del in Quux += " R",
// tests that configurations are properly registered, enabling delegation from p to q
demo += (del in Pippy).value
)
override def projectSettings = Seq(
// tests proper ordering: R requires Q, so Q settings should come first
Quux / del += " R",
// tests that configurations are properly registered, enabling delegation from p to q
demo += (del in Pippy).value
)
}
// This is an opt-in plugin with a requirement
// Unless explicitly loaded by the build user, this will not be activated.
object S extends AutoPlugin
{
override def requires = Q
override def trigger = noTrigger
object S extends AutoPlugin {
override def requires = Q
override def trigger = noTrigger
override def projectSettings = Seq(
del in Quux += " S",
organization := "S"
)
override def projectSettings = Seq(
Quux / del += " S",
organization := "S"
)
}

View File

@ -1,7 +1,5 @@
organization in ThisBuild := "org.example"
ThisBuild / organization := "org.example"
// We have to use snapshot because this is publishing to our local ivy cache instead of
// an integration cache, so we're in danger land.
version in ThisBuild := "3.4-SNAPSHOT"
ThisBuild / version := "3.4-SNAPSHOT"

View File

@ -1,5 +1,5 @@
buildDependencies in Global :=
(buildDependencies in Global).value.addClasspath(
(thisProjectRef in LocalProject("a")).value,
Global / buildDependencies :=
(Global / buildDependencies).value.addClasspath(
(LocalProject("a") / thisProjectRef).value,
ResolvedClasspathDependency(thisProjectRef.value, None)
)

View File

@ -7,12 +7,12 @@ lazy val root = (project in file(".")).
lazy val sub: Project = project.
dependsOn(LocalProject("root")).
settings(
name := (name in LocalProject("root")).value + "sub"
name := (LocalProject("root") / name).value + "sub"
)
lazy val foo: Project = project.
aggregate(LocalProject("root")).
dependsOn(LocalProject("root")).
settings(List(
name := (name in LocalProject("root")).value + "foo"
name := (LocalProject("root") / name).value + "foo"
): _*)

View File

@ -1,8 +1,8 @@
val baseSbt = "1."
val buildCrossList = List("2.10.7", "2.11.12", "2.12.12")
scalaVersion in ThisBuild := "2.12.12"
crossScalaVersions in ThisBuild := buildCrossList
(ThisBuild / scalaVersion) := "2.12.12"
(ThisBuild / crossScalaVersions) := buildCrossList
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
@ -16,8 +16,8 @@ lazy val root = (project in file("."))
lazy val app = (project in file("app"))
def mkCheck(scalaBinV: String, sbtBinVer: String, sbtVerPrefix: String) = Def.task {
val crossV = (sbtVersion in pluginCrossBuild).value
val crossBinV = (sbtBinaryVersion in pluginCrossBuild).value
val crossV = (pluginCrossBuild / sbtVersion).value
val crossBinV = (pluginCrossBuild / sbtBinaryVersion).value
val sv = projectID.value.extraAttributes("e:scalaVersion")
assert(sbtVersion.value startsWith baseSbt, s"Wrong sbt version: ${sbtVersion.value}")
assert(sv == scalaBinV, s"Wrong e:scalaVersion: $sv")
@ -33,8 +33,8 @@ def mkCheck(scalaBinV: String, sbtBinVer: String, sbtVerPrefix: String) = Def.ta
assert(plugSbtV == sbtBinVer, s"Wrong plugin sbtVersion: $plugSbtV")
// crossScalaVersions in app should not be affected, per se or after ^^
val appCrossScalaVersions = (crossScalaVersions in app).value.toList
val appScalaVersion = (scalaVersion in app).value
val appCrossScalaVersions = (app / crossScalaVersions).value.toList
val appScalaVersion = (app / scalaVersion).value
assert(appCrossScalaVersions == buildCrossList, s"Wrong `crossScalaVersions in app`: $appCrossScalaVersions")
assert(appScalaVersion startsWith "2.12", s"Wrong `scalaVersion in app`: $appScalaVersion")
}

View File

@ -1,6 +1,6 @@
lazy val root = (project in file("."))
.settings(
sbtPlugin := true,
sbtVersion in pluginCrossBuild := "0.13.15",
pluginCrossBuild / sbtVersion := "0.13.15",
resolvers += Resolver.typesafeIvyRepo("releases")
)

View File

@ -3,7 +3,7 @@ ThisBuild / csrCacheDirectory := (ThisBuild / baseDirectory).value / "coursier-c
val commonSettings = Seq(
organization := "com.example",
version := "0.1.0",
ivyPaths := IvyPaths((baseDirectory in LocalRootProject).value, Some((target in LocalRootProject).value / "ivy-cache"))
ivyPaths := IvyPaths((LocalRootProject / baseDirectory).value, Some((LocalRootProject / target).value / "ivy-cache"))
)
lazy val app = (project in file("app")).

View File

@ -12,8 +12,8 @@ lazy val root = (project in file("."))
.settings(
lintBuildTest := {
val state = Keys.state.value
val includeKeys = (lintIncludeFilter in Global).value
val excludeKeys = (lintExcludeFilter in Global).value
val includeKeys = (Global / lintIncludeFilter).value
val excludeKeys = (Global / lintExcludeFilter).value
val result = sbt.internal.LintUnused.lintUnused(state, includeKeys, excludeKeys)
result foreach {
case (_, "ThisBuild / doc / scalacOptions", _) => ()

View File

@ -6,8 +6,8 @@
s.put(key, previous + 1)
}
Seq(
onLoad in Global ~= (f(loadCount) compose _),
onUnload in Global ~= (f(unloadCount) compose _)
Global / onLoad ~= (f(loadCount) compose _),
Global / onUnload ~= (f(unloadCount) compose _)
)
}

View File

@ -2,15 +2,17 @@ val rootRef = LocalProject("root")
val sub = project
val superRoot = project in file("super") dependsOn rootRef
val root = project in file(".") dependsOn (sub % "provided->test") settings (
TaskKey[Unit]("check") := {
check0((fullClasspath in (sub, Test)).value, "sub test", true)
check0((fullClasspath in (superRoot, Compile)).value, "superRoot main", false)
check0((fullClasspath in (rootRef, Compile)).value, "root main", true)
check0((fullClasspath in (rootRef, Runtime)).value, "root runtime", false)
check0((fullClasspath in (rootRef, Test)).value, "root test", true)
}
)
val root = (project in file(".")).
dependsOn(sub % "provided->test").
settings (
TaskKey[Unit]("check") := {
check0((sub / Test / fullClasspath).value, "sub test", true)
check0((superRoot / Compile / fullClasspath).value, "superRoot main", false)
check0((rootRef / Compile / fullClasspath).value, "root main", true)
check0((rootRef / Runtime / fullClasspath).value, "root runtime", false)
check0((rootRef / Test / fullClasspath).value, "root test", true)
}
)
def check0(cp: Seq[Attributed[File]], label: String, shouldSucceed: Boolean): Unit = {
import sbt.internal.inc.classpath.ClasspathUtilities

View File

@ -34,6 +34,6 @@ lazy val root = project.
val t = testFile.value
IO.append(t, "2")
},
foo := Def.sequential(compile in Compile, sideEffect0, sideEffect1, sideEffect2, test in Test, bar).value,
foo := Def.sequential(Compile / compile, sideEffect0, sideEffect1, sideEffect2, Test / test, bar).value,
bar := 1
)

View File

@ -14,7 +14,7 @@ lazy val root = (project in file("."))
},
libraryDependencies += scalatest % Test,
// testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-f", "result.txt", "-eNDXEHLO")
testOptions in Configurations.Test ++= {
Configurations.Test / testOptions ++= {
def args(path: String, args: String*): Seq[TestOption] =
if(file(path).exists) Tests.Argument(args : _*) :: Nil
else Nil

View File

@ -24,22 +24,22 @@ val p1 = project
.configs(CustomConfigs: _*)
.settings(
t := {
(compile in Config_0).value
(compile in Config_1).value
(compile in Config_2).value
(compile in Config_3).value
(compile in Config_4).value
(compile in Config_5).value
(compile in Config_6).value
(compile in Config_7).value
(compile in Config_8).value
(compile in Config_9).value
(compile in Config_10).value
(compile in Config_11).value
(compile in Config_12).value
(compile in Config_13).value
(compile in Config_14).value
(compile in Config_15).value
(Config_0 / compile).value
(Config_1 / compile).value
(Config_2 / compile).value
(Config_3 / compile).value
(Config_4 / compile).value
(Config_5 / compile).value
(Config_6 / compile).value
(Config_7 / compile).value
(Config_8 / compile).value
(Config_9 / compile).value
(Config_10 / compile).value
(Config_11 / compile).value
(Config_12 / compile).value
(Config_13 / compile).value
(Config_14 / compile).value
(Config_15 / compile).value
}
)
.settings(CustomConfigs.flatMap(c => inConfig(c)(Defaults.testSettings)))

View File

@ -1,5 +1,5 @@
testGrouping := {
val tests = (definedTests in Test).value
val tests = (Test / definedTests).value
tests map { test =>
new Tests.Group(
name = test.name,

View File

@ -7,7 +7,7 @@ val check = taskKey[Unit]("Check that tests are executed in parallel")
lazy val root = (project in file("."))
.settings(
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test,
fork in Test := true,
Test / fork := true,
check := {
val nbProc = java.lang.Runtime.getRuntime().availableProcessors()
val log = streams.value.log

View File

@ -6,7 +6,7 @@ testFrameworks := new TestFramework("build.MyFramework") :: Nil
fork := true
definedTests in Test += new sbt.TestDefinition(
Test / definedTests += new sbt.TestDefinition(
"my",
// marker fingerprint since there are no test classes
// to be discovered by sbt:

View File

@ -16,8 +16,8 @@ ThisBuild / organization := "org.example"
lazy val root = (project in file("."))
.settings(
testGrouping in Test := {
val tests = (definedTests in Test).value
Test / testGrouping := {
val tests = (Test / definedTests).value
assert(tests.size == 3)
for (idx <- 0 until groups) yield
new Group(
@ -32,7 +32,7 @@ lazy val root = (project in file("."))
file(groupPrefix(i) + j)
val (exist, absent) = files.partition(_.exists)
exist.foreach(_.delete())
if(absent.nonEmpty)
if (absent.nonEmpty)
sys.error("Files were not created:\n\t" + absent.mkString("\n\t"))
},
concurrentRestrictions := Tags.limit(Tags.ForkedTestGroup, 2) :: Nil,

View File

@ -10,5 +10,5 @@ $ copy-file changes/Failure.scala src/test/scala/Failure.scala
-> testOnly com.foo.junit.test.blah.Failure
> testOnly com.foo.junit.test.blah.Success
> set fork in Test := true
> set Test / fork := true
> testOnly com.foo.junit.test.blah.Success

View File

@ -3,14 +3,14 @@ val a = project.settings(version := "2.8.1")
val trySetEvery = taskKey[Unit]("Tests \"set every\"")
trySetEvery := {
val s = state.value
val extracted = Project.extract(s)
import extracted._
val allProjs = structure.allProjectRefs
val Some(aProj) = allProjs.find(_.project == "a")
val aVer = (version in aProj get structure.data).get
if (aVer != "1.0") {
println("Version of project a: " + aVer + ", expected: 1.0")
sys.error("\"set every\" did not change the version of all projects.")
}
val s = state.value
val extracted = Project.extract(s)
import extracted._
val allProjs = structure.allProjectRefs
val Some(aProj) = allProjs.find(_.project == "a")
val aVer = ((aProj / version) get structure.data).get
if (aVer != "1.0") {
println("Version of project a: " + aVer + ", expected: 1.0")
sys.error("\"set every\" did not change the version of all projects.")
}
}

View File

@ -16,29 +16,34 @@ object Build {
val Seq(stringFile, string) = Def.spaceDelimited().parsed
assert(IO.read(file(stringFile)) == string)
}
lazy val foo = project.settings(
watchStartMessage := { (count: Int, _, _) => Some(s"FOO $count") },
Compile / compile / watchTriggers += baseDirectory.value.toGlob / "foo.txt",
Compile / compile / watchStartMessage := { (count: Int, _, _) =>
// this checks that Compile / compile / watchStartMessage
// is preferred to Compile / watchStartMessage
val outputFile = baseDirectory.value / "foo.txt"
IO.write(outputFile, "compile")
Some(s"compile $count")
},
Compile / watchStartMessage := { (count: Int, _, _) => Some(s"Compile $count") },
Runtime / watchStartMessage := { (count: Int, _, _) => Some(s"Runtime $count") },
setStringValue := {
val _ = (fileInputs in (bar, setStringValue)).value
setStringValueImpl.evaluated
},
checkStringValue := checkStringValueImpl.evaluated,
watchOnFileInputEvent := { (_, _) => Watch.CancelWatch }
)
lazy val bar = project.settings(
fileInputs in setStringValue += baseDirectory.value.toGlob / "foo.txt"
)
lazy val root = (project in file(".")).aggregate(foo, bar).settings(
watchOnFileInputEvent := { (_, _) => Watch.CancelWatch }
)
lazy val foo = project
.settings(
watchStartMessage := { (count: Int, _, _) => Some(s"FOO $count") },
Compile / compile / watchTriggers += baseDirectory.value.toGlob / "foo.txt",
Compile / compile / watchStartMessage := { (count: Int, _, _) =>
// this checks that Compile / compile / watchStartMessage
// is preferred to Compile / watchStartMessage
val outputFile = baseDirectory.value / "foo.txt"
IO.write(outputFile, "compile")
Some(s"compile $count")
},
Compile / watchStartMessage := { (count: Int, _, _) => Some(s"Compile $count") },
Runtime / watchStartMessage := { (count: Int, _, _) => Some(s"Runtime $count") },
setStringValue := {
val _ = (bar / setStringValue / fileInputs).value
setStringValueImpl.evaluated
},
checkStringValue := checkStringValueImpl.evaluated,
watchOnFileInputEvent := { (_, _) => Watch.CancelWatch }
)
lazy val bar = project
.settings(
setStringValue / fileInputs += baseDirectory.value.toGlob / "foo.txt"
)
lazy val root = (project in file("."))
.aggregate(foo, bar).settings(
watchOnFileInputEvent := { (_, _) => Watch.CancelWatch }
)
}

View File

@ -33,7 +33,7 @@ object Build {
lazy val foo = project
.settings(
setStringValue := {
val _ = (fileInputs in (bar, setStringValue)).value
val _ = (bar / setStringValue / fileInputs).value
setStringValueImpl.evaluated
},
checkStringValue := checkStringValueImpl.evaluated,
@ -92,6 +92,7 @@ object Build {
assert(testTriggers == compileTriggers)
},
)
lazy val root = (project in file("."))
.aggregate(foo, bar)
.settings(