Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Task instead of T when constructing targets and other tasks #3565

Merged
merged 14 commits into from
Sep 18, 2024
4 changes: 2 additions & 2 deletions bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.bsp

import mill.api.{Ctx, PathRef}
import mill.{Agg, T}
import mill.{Agg, T, Task}
import mill.define.{Command, Discover, ExternalModule}
import mill.main.BuildInfo
import mill.eval.Evaluator
Expand All @@ -12,7 +12,7 @@ object BSP extends ExternalModule with CoursierModule {

lazy val millDiscover: Discover = Discover[this.type]

private def bspWorkerLibs: T[Agg[PathRef]] = T {
private def bspWorkerLibs: T[Agg[PathRef]] = Task {
millProjectModule("mill-bsp-worker", repositoriesTask())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ trait BintrayPublishModule extends PublishModule {

def bintrayRepo: String

def bintrayPackage = T { artifactId() }
def bintrayPackage: T[String] = Task { artifactId() }

def bintrayPublishArtifacts: T[BintrayPublishData] = T {
def bintrayPublishArtifacts: T[BintrayPublishData] = Task {
val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts()
BintrayPublishData(artifactInfo, artifacts, bintrayPackage())
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
def linkerMode: T[Option[BloopConfig.LinkerMode]] = None

object bloop extends MillModule {
def config = T {
def config = Task {
new BloopOps(self).bloop.config()
}
}
Expand All @@ -85,7 +85,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
override def millOuterCtx = jm.millOuterCtx

object bloop extends MillModule {
def config = T { outer.bloopConfig(jm) }
def config = Task { outer.bloopConfig(jm) }

def writeConfigFile(): Command[(String, PathRef)] = T.command {
os.makeDir.all(bloopDir)
Expand All @@ -96,7 +96,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
}

@deprecated("Use writeConfigFile instead.", "Mill after 0.10.9")
def writeConfig: Target[(String, PathRef)] = T {
def writeConfig: T[(String, PathRef)] = Task {
writeConfigFile()()
}
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.contrib.buildinfo

import mill.T
import mill.{T, Task}
import mill.api.PathRef
import mill.scalalib.{JavaModule, ScalaModule}
import mill.scalanativelib.ScalaNativeModule
Expand Down Expand Up @@ -39,7 +39,7 @@ trait BuildInfo extends JavaModule {
if (buildInfoStaticCompiled) super.resources
else T.sources { super.resources() ++ Seq(buildInfoResources()) }

def buildInfoResources = T {
def buildInfoResources = Task {
val p = new java.util.Properties
for (v <- buildInfoMembers()) p.setProperty(v.key, v.value)

Expand All @@ -59,11 +59,11 @@ trait BuildInfo extends JavaModule {

private def isScala = this.isInstanceOf[ScalaModule]

override def generatedSources = T {
override def generatedSources = Task {
super.generatedSources() ++ buildInfoSources()
}

def buildInfoSources = T {
def buildInfoSources = Task {
if (buildInfoMembers().isEmpty) Nil
else {
val code = if (buildInfoStaticCompiled) BuildInfo.staticCompiledCodegen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ trait CheckstyleModule extends JavaModule {
/**
* Classpath for running Checkstyle.
*/
def checkstyleClasspath: T[Loose.Agg[PathRef]] = T {
def checkstyleClasspath: T[Loose.Agg[PathRef]] = Task {
defaultResolver().resolveDeps(
Agg(ivy"com.puppycrawl.tools:checkstyle:${checkstyleVersion()}")
)
Expand All @@ -86,35 +86,35 @@ trait CheckstyleModule extends JavaModule {
/**
* Checkstyle configuration file. Defaults to `checkstyle-config.xml`.
*/
def checkstyleConfig: T[PathRef] = T {
def checkstyleConfig: T[PathRef] = Task {
PathRef(T.workspace / "checkstyle-config.xml")
}

/**
* Checkstyle output format (` plain | sarif | xml `). Defaults to `plain`.
*/
def checkstyleFormat: T[String] = T {
def checkstyleFormat: T[String] = Task {
"plain"
}

/**
* Additional arguments for Checkstyle.
*/
def checkstyleOptions: T[Seq[String]] = T {
def checkstyleOptions: T[Seq[String]] = Task {
Seq.empty[String]
}

/**
* Checkstyle output report.
*/
def checkstyleOutput: T[PathRef] = T {
def checkstyleOutput: T[PathRef] = Task {
PathRef(T.dest / s"checkstyle-output.${checkstyleFormat()}")
}

/**
* Checkstyle version.
*/
def checkstyleVersion: T[String] = T {
def checkstyleVersion: T[String] = Task {
"10.18.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ trait CheckstyleXsltModule extends CheckstyleModule {
*
* }}}
*/
def checkstyleXsltReports: T[Set[CheckstyleXsltReport]] = T {
def checkstyleXsltReports: T[Set[CheckstyleXsltReport]] = Task {
val dir = checkstyleXsltfFolder().path

if (os.exists(dir)) {
Expand Down
4 changes: 2 additions & 2 deletions contrib/docker/src/mill/contrib/docker/DockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ trait DockerModule { outer: JavaModule =>
*/
def executable: T[String] = "docker"

def dockerfile: T[String] = T {
def dockerfile: T[String] = Task {
val jarName = assembly().path.last
val labelRhs = labels()
.map { case (k, v) =>
Expand Down Expand Up @@ -149,7 +149,7 @@ trait DockerModule { outer: JavaModule =>
(pullBaseImage(), imageHash())
}

final def build = T {
final def build = Task {
val dest = T.dest

val asmPath = outer.assembly().path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.contrib.errorprone

import mill.api.PathRef
import mill.{Agg, T}
import mill.{Agg, T, Task}
import mill.scalalib.{Dep, DepSyntax, JavaModule}

import java.io.File
Expand All @@ -21,7 +21,7 @@ trait ErrorProneModule extends JavaModule {
/**
* The dependencies of the `error-prone` compiler plugin.
*/
def errorProneDeps: T[Agg[Dep]] = T {
def errorProneDeps: T[Agg[Dep]] = Task {
Agg(
ivy"com.google.errorprone:error_prone_core:${errorProneVersion()}"
)
Expand All @@ -30,14 +30,14 @@ trait ErrorProneModule extends JavaModule {
/**
* The classpath of the `error-prone` compiler plugin.
*/
def errorProneClasspath: T[Agg[PathRef]] = T {
def errorProneClasspath: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(errorProneDeps())
}

/**
* Options used to enable and configure the `eror-prone` plugin in the Java compiler.
*/
def errorProneJavacEnableOptions: T[Seq[String]] = T {
def errorProneJavacEnableOptions: T[Seq[String]] = Task {
val processorPath = errorProneClasspath().map(_.path).mkString(File.pathSeparator)
val enableOpts = Seq(
"-XDcompilePolicy=simple",
Expand Down Expand Up @@ -65,12 +65,12 @@ trait ErrorProneModule extends JavaModule {
*
* Those are documented as "flags" at https://errorprone.info/docs/flags
*/
def errorProneOptions: T[Seq[String]] = T { Seq.empty[String] }
def errorProneOptions: T[Seq[String]] = Task { Seq.empty[String] }

/**
* Appends the [[errorProneJavacEnableOptions]] to the Java compiler options.
*/
override def mandatoryJavacOptions: T[Seq[String]] = T {
override def mandatoryJavacOptions: T[Seq[String]] = Task {
super.mandatoryJavacOptions() ++ errorProneJavacEnableOptions()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.contrib.errorprone

import mill.T
import mill.{T, Task}
import mill.scalalib.JavaModule
import mill.testkit.{TestBaseModule, UnitTester}
import os.Path
Expand Down
6 changes: 3 additions & 3 deletions contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.flywaydb.core.internal.configuration.{ConfigUtils => flyway}
import org.flywaydb.core.internal.info.MigrationInfoDumper
import scala.jdk.CollectionConverters._

import mill.{Agg, T}
import mill.{Agg, T, Task}
import mill.api.PathRef
import mill.define.Command
import mill.scalalib.{Dep, JavaModule}
Expand All @@ -22,13 +22,13 @@ trait FlywayModule extends JavaModule {
def flywayUrl: T[String]
def flywayUser: T[String] = T("")
def flywayPassword: T[String] = T("")
def flywayFileLocations: T[Seq[PathRef]] = T {
def flywayFileLocations: T[Seq[PathRef]] = Task {
resources().map(pr => PathRef(pr.path / "db/migration", pr.quick))
}

def flywayDriverDeps: T[Agg[Dep]]

def jdbcClasspath = T {
def jdbcClasspath = Task {
defaultResolver().resolveDeps(flywayDriverDeps())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.contrib.gitlab

import mill.T
import mill.{T, Task}
import mill.api.Result.Failure
import mill.scalalib.publish.PomSettings
import mill.testkit.UnitTester
Expand Down
6 changes: 3 additions & 3 deletions contrib/jmh/src/mill/contrib/jmh/JmhModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait JmhModule extends JavaModule {
def listJmhBenchmarks(args: String*) = runJmh(("-l" +: args): _*)

def compileGeneratedSources =
T {
Task {
val dest = T.ctx().dest
val (sourcesDir, _) = generateBenchmarkSources()
val sources = os.walk(sourcesDir).filter(os.isFile)
Expand All @@ -70,7 +70,7 @@ trait JmhModule extends JavaModule {

// returns sources and resources directories
def generateBenchmarkSources =
T {
Task {
val dest = T.ctx().dest

val sourcesDir = dest / "jmh_sources"
Expand All @@ -95,7 +95,7 @@ trait JmhModule extends JavaModule {
(sourcesDir, resourcesDir)
}

def generatorDeps = T {
def generatorDeps = Task {
defaultResolver().resolveDeps(
Agg(ivy"org.openjdk.jmh:jmh-generator-bytecode:${jmhGeneratorByteCodeVersion()}")
)
Expand Down
22 changes: 11 additions & 11 deletions contrib/playlib/src/mill/playlib/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package mill.playlib

import mill.{Agg, T}
import mill.{Agg, Task}
import mill.scalalib._

private[playlib] trait Dependencies extends ScalaModule with Version {
def core = T { component("play") }
def guice = T { component("play-guice") }
def server = T { component("play-server") }
def logback = T { component("play-logback") }
def evolutions = T { component("play-jdbc-evolutions") }
def jdbc = T { component("play-jdbc") }
def filters = T { component("filters-helpers") }
def ws = T { component("play-ahc-ws") }
def caffeine = T { component("play-caffeine-cache") }
def core = Task { component("play") }
def guice = Task { component("play-guice") }
def server = Task { component("play-server") }
def logback = Task { component("play-logback") }
def evolutions = Task { component("play-jdbc-evolutions") }
def jdbc = Task { component("play-jdbc") }
def filters = Task { component("filters-helpers") }
def ws = Task { component("play-ahc-ws") }
def caffeine = Task { component("play-caffeine-cache") }

override def ivyDeps = T {
override def ivyDeps = Task {
super.ivyDeps() ++ Agg(
core(),
guice(),
Expand Down
4 changes: 2 additions & 2 deletions contrib/playlib/src/mill/playlib/PlayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import mill.{Agg, Args, T}

trait PlayApiModule extends Dependencies with Router with Server {
trait PlayTests extends ScalaTests with TestModule.ScalaTest {
override def ivyDeps = T {
override def ivyDeps = Task {
val scalatestPlusPlayVersion = playMinorVersion() match {
case Versions.PLAY_2_6 => "3.1.3"
case Versions.PLAY_2_7 => "4.0.3"
Expand All @@ -24,7 +24,7 @@ trait PlayApiModule extends Dependencies with Router with Server {

}
trait PlayModule extends PlayApiModule with Static with Twirl {
override def twirlVersion = T {
override def twirlVersion: T[String] = Task {
playMinorVersion() match {
case "2.6" => "1.3.16"
case "2.7" => "1.4.2"
Expand Down
4 changes: 2 additions & 2 deletions contrib/playlib/src/mill/playlib/Router.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.playlib

import mill.T
import mill.Task

private[playlib] trait Router extends RouterModule with Layout {
override def routes = T { conf() }
override def routes = Task { conf() }
}
14 changes: 7 additions & 7 deletions contrib/playlib/src/mill/playlib/RouterModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import mill.util.Util.millProjectModule
import mill.playlib.api.RouteCompilerType
import mill.scalalib._
import mill.scalalib.api._
import mill.{Agg, T}
import mill.{Agg, T, Task}

trait RouterModule extends ScalaModule with Version {

def routes: T[Seq[PathRef]] = T.sources { millSourcePath / "routes" }

def routeFiles = T {
def routeFiles = Task {
val paths = routes().flatMap(file => os.walk(file.path))
val routeFiles = paths.filter(_.ext == "routes") ++ paths.filter(_.last == "routes")
routeFiles.map(f => PathRef(f))
Expand Down Expand Up @@ -45,7 +45,7 @@ trait RouterModule extends ScalaModule with Version {
*/
def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator

def routerClasspath: T[Agg[PathRef]] = T {
def routerClasspath: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(
playMinorVersion() match {
case "2.6" | "2.7" | "2.8" =>
Expand Down Expand Up @@ -74,7 +74,7 @@ trait RouterModule extends ScalaModule with Version {
)
}

def playRouteCompilerWorkerClasspath = T {
def playRouteCompilerWorkerClasspath = Task {
millProjectModule(
s"mill-contrib-playlib-worker-${playMinorVersion()}",
repositoriesTask(),
Expand All @@ -85,15 +85,15 @@ trait RouterModule extends ScalaModule with Version {
)
}

def playRouterToolsClasspath = T {
def playRouterToolsClasspath = Task {
playRouteCompilerWorkerClasspath() ++ routerClasspath()
}

def routerClasses = T {
def routerClasses = Task {
Seq(compileRouter().classes)
}

override def generatedSources = T {
override def generatedSources = Task {
super.generatedSources() ++ routerClasses()
}
}
Loading
Loading