1+ //| mvnDeps:
2+ //| - com.github.lolgab::mill-mima_mill1:0.2.0
3+ //| - "com.lihaoyi::mill-contrib-twirllib:$MILL_VERSION"
4+
15package build
26
37import mill._, scalalib._, scalajslib._, publish._
4- import mill.scalalib.api.ZincWorkerUtil
5-
6- import $packages._
7- import $file.ci.upload
8- import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
9- import $ivy.`com.github.lolgab::mill-mima::0.0.23`
10- import de.tobiasroeser.mill.vcs.version.VcsVersion
8+ import mill.javalib.api.JvmWorkerUtil
9+ import mill.util.VcsVersion
1110
1211val scala213 = "2.13.15"
1312val scala212 = "2.12.20"
@@ -18,7 +17,7 @@ val communityBuildDottyVersion = sys.props.get("dottyVersion").toList
1817val scalaVersions = List(scala212, scala213, scala3) ++ communityBuildDottyVersion
1918
2019trait CaskModule extends CrossScalaModule with PublishModule{
21- def isScala3 = ZincWorkerUtil .isScala3(crossScalaVersion)
20+ def isScala3 = JvmWorkerUtil .isScala3(crossScalaVersion)
2221
2322 def publishVersion = VcsVersion.vcsState().format()
2423
@@ -35,22 +34,22 @@ trait CaskModule extends CrossScalaModule with PublishModule{
3534}
3635
3736trait CaskMainModule extends CaskModule {
38- def ivyDeps = T {
39- Agg (
40- ivy "io.undertow:undertow-core:2.3.18.Final",
41- ivy "com.lihaoyi::upickle:4.0.2"
37+ def mvnDeps = Task {
38+ Seq (
39+ mvn "io.undertow:undertow-core:2.3.18.Final",
40+ mvn "com.lihaoyi::upickle:4.0.2"
4241 ) ++
43- Agg .when(!isScala3)(ivy "org.scala-lang:scala-reflect:$crossScalaVersion")
42+ Option .when(!isScala3)(mvn "org.scala-lang:scala-reflect:$crossScalaVersion")
4443 }
4544
46- def compileIvyDeps = Agg .when(!isScala3)(ivy "com.lihaoyi:::acyclic:0.3.15")
47- def scalacOptions = Agg .when(!isScala3)("-P:acyclic:force").toSeq
48- def scalacPluginIvyDeps = Agg .when(!isScala3)(ivy "com.lihaoyi:::acyclic:0.3.15")
45+ def compileMvnDeps = Option .when(!isScala3)(mvn "com.lihaoyi:::acyclic:0.3.15").toSeq
46+ def scalacOptions = Option .when(!isScala3)("-P:acyclic:force").toSeq
47+ def scalacPluginMvnDeps = Option .when(!isScala3)(mvn "com.lihaoyi:::acyclic:0.3.15").toSeq
4948
50- object test extends ScalaTests with TestModule.Utest{
51- def ivyDeps = Agg (
52- ivy "com.lihaoyi::utest::0.8.4",
53- ivy "com.lihaoyi::requests::0.9.0"
49+ object test extends ScalaTests with TestModule.Utest {
50+ def mvnDeps = Seq (
51+ mvn "com.lihaoyi::utest::0.8.4",
52+ mvn "com.lihaoyi::requests::0.9.0"
5453 )
5554 }
5655 def moduleDeps = Seq(cask.util.jvm(crossScalaVersion))
@@ -59,35 +58,35 @@ trait CaskMainModule extends CaskModule {
5958object cask extends Cross[CaskMainModule](scalaVersions) {
6059 object util extends Module {
6160 trait UtilModule extends CaskModule with PlatformScalaModule{
62- def ivyDeps = Agg (
63- ivy "com.lihaoyi::sourcecode:0.4.2",
64- ivy "com.lihaoyi::pprint:0.9.0",
65- ivy "com.lihaoyi::geny:1.1.1"
61+ def mvnDeps = Seq (
62+ mvn "com.lihaoyi::sourcecode:0.4.2",
63+ mvn "com.lihaoyi::pprint:0.9.0",
64+ mvn "com.lihaoyi::geny:1.1.1"
6665 )
6766 }
6867
6968 object jvm extends Cross[UtilJvmModule](scalaVersions)
7069 trait UtilJvmModule extends UtilModule {
71- def ivyDeps = super.ivyDeps () ++ Agg (
72- ivy "com.lihaoyi::castor::0.3.0",
73- ivy "org.java-websocket:Java-WebSocket:1.5.3"
70+ def mvnDeps = super.mvnDeps () ++ Seq (
71+ mvn "com.lihaoyi::castor::0.3.0",
72+ mvn "org.java-websocket:Java-WebSocket:1.5.3"
7473 )
7574 }
7675
7776 object js extends Cross[UtilJsModule](scala213)
7877 trait UtilJsModule extends UtilModule with ScalaJSModule {
7978 def scalaJSVersion = scalaJS
80- def ivyDeps = super.ivyDeps () ++ Agg (
81- ivy "com.lihaoyi::castor::0.3.0",
82- ivy "org.scala-js::scalajs-dom::2.4.0"
79+ def mvnDeps = super.mvnDeps () ++ Seq (
80+ mvn "com.lihaoyi::castor::0.3.0",
81+ mvn "org.scala-js::scalajs-dom::2.4.0"
8382 )
8483 }
8584 }
8685}
8786
8887trait BenchmarkModule extends CrossScalaModule {
8988 def moduleDeps = Seq(cask(crossScalaVersion))
90- def ivyDeps = Agg [Dep](
89+ def mvnDeps = Seq [Dep](
9190 )
9291}
9392
@@ -149,8 +148,8 @@ object benchmark extends Cross[BenchmarkModule](build.scalaVersions) with RunMod
149148 println(results.out.text())
150149 }
151150
152- def runBenchmarks() = T.command {
153- val projectRoot = T.workspace
151+ def runBenchmarks() = Task.Command {
152+ val projectRoot = mill.api.BuildCtx.workspaceRoot
154153 if (os.proc("which", "wrk").call(check = false).exitCode != 0) {
155154 println("Error: wrk is not installed. Please install wrk first.")
156155 sys.exit(1)
@@ -169,119 +168,123 @@ object benchmark extends Cross[BenchmarkModule](build.scalaVersions) with RunMod
169168}
170169
171170trait LocalModule extends CrossScalaModule{
172- override def millSourcePath = super.millSourcePath / "app"
171+ override def moduleDir = super.moduleDir / "app"
173172 def moduleDeps = Seq(cask(crossScalaVersion))
174173}
175174
176175
177176
178- def zippedExamples = T {
179- val vcsState = VcsVersion.vcsState()
180-
181- val releaseTag = vcsState.lastTag.getOrElse("")
182- val label = vcsState.format()
183-
184- val examples = Seq(
185- build.example.compress.millSourcePath,
186- build.example.compress2.millSourcePath,
187- build.example.compress3.millSourcePath,
188- build.example.cookies.millSourcePath,
189- build.example.decorated.millSourcePath,
190- build.example.decorated2.millSourcePath,
191- build.example.decoratedContext.millSourcePath,
192- build.example.endpoints.millSourcePath,
193- build.example.formJsonPost.millSourcePath,
194- build.example.httpMethods.millSourcePath,
195- build.example.minimalApplication.millSourcePath,
196- build.example.minimalApplication2.millSourcePath,
197- build.example.minimalApplicationWithLoom.millSourcePath,
198- build.example.redirectAbort.millSourcePath,
199- build.example.scalatags.millSourcePath,
200- build.example.staticFiles.millSourcePath,
201- build.example.staticFilesWithLoom.millSourcePath,
202- build.example.staticFiles2.millSourcePath,
203- build.example.todo.millSourcePath,
204- build.example.todoApi.millSourcePath,
205- build.example.todoDb.millSourcePath,
206- build.example.todoDbWithLoom.millSourcePath,
207- build.example.twirl.millSourcePath,
208- build.example.variableRoutes.millSourcePath,
209- build.example.queryParams.millSourcePath,
210- build.example.websockets.millSourcePath,
211- build.example.websockets2.millSourcePath,
212- build.example.websockets3.millSourcePath,
213- build.example.websockets4.millSourcePath,
214- build.example.multipartFormSubmission.millSourcePath,
215- )
216-
217- for (example <- examples) yield {
218- val f = T.ctx().dest
219- val last = example.last + "-" + label
220- os.copy(example, f / last)
221- os.copy(T.workspace / ".mill-version", f / last / ".mill-version")
222- os.write.over(f / last / "mill", os.read(T.workspace / "mill"))
223- os.proc("chmod", "+x", f / last / "mill").call(f / last)
224- os.move(f / last / "package.mill", f / last / "build.mill")
225- os.write.over(
226- f / last / "build.mill",
227- os.read(f / last / "build.mill")
228- .replaceAll("package build.*", "package build")
229- .replaceAll("def moduleDeps =.*", "")
230- .replaceAll("app =>", "")
231- .replaceFirst(
232- "object app extends.*\ntrait AppModule extends CrossScalaModule(.*)\\{",
233- s"object app extends ScalaModule $$1\\{\n def scalaVersion = \"${scala213}\"")
234- .replaceAll("build.scala3", s"\"${scala3}\"")
235- .replaceFirst(
236- "def ivyDeps = Agg\\[Dep\\]\\(",
237- "def ivyDeps = Agg(\n ivy\"com.lihaoyi::cask:" + releaseTag + "\","
238- )
177+ def zippedExamples = Task {
178+ mill.api.BuildCtx.withFilesystemCheckerDisabled {
179+ val vcsState = VcsVersion.vcsState()
180+
181+ val releaseTag = vcsState.lastTag.getOrElse("")
182+ val label = vcsState.format()
183+
184+ val examples = Seq(
185+ build.example.compress.moduleDir,
186+ build.example.compress2.moduleDir,
187+ build.example.compress3.moduleDir,
188+ build.example.cookies.moduleDir,
189+ build.example.decorated.moduleDir,
190+ build.example.decorated2.moduleDir,
191+ build.example.decoratedContext.moduleDir,
192+ build.example.endpoints.moduleDir,
193+ build.example.formJsonPost.moduleDir,
194+ build.example.httpMethods.moduleDir,
195+ build.example.minimalApplication.moduleDir,
196+ build.example.minimalApplication2.moduleDir,
197+ build.example.minimalApplicationWithLoom.moduleDir,
198+ build.example.redirectAbort.moduleDir,
199+ build.example.scalatags.moduleDir,
200+ build.example.staticFiles.moduleDir,
201+ build.example.staticFilesWithLoom.moduleDir,
202+ build.example.staticFiles2.moduleDir,
203+ build.example.todo.moduleDir,
204+ build.example.todoApi.moduleDir,
205+ build.example.todoDb.moduleDir,
206+ build.example.todoDbWithLoom.moduleDir,
207+ build.example.twirl.moduleDir,
208+ build.example.variableRoutes.moduleDir,
209+ build.example.queryParams.moduleDir,
210+ build.example.websockets.moduleDir,
211+ build.example.websockets2.moduleDir,
212+ build.example.websockets3.moduleDir,
213+ build.example.websockets4.moduleDir,
214+ build.example.multipartFormSubmission.moduleDir,
239215 )
240216
241- os.zip(f / s"$last.zip", Seq(f / last))
242- PathRef(f / s"$last.zip")
217+ for (example <- examples) yield {
218+ val f = Task.ctx().dest
219+ val last = example.last + "-" + label
220+ os.copy(example, f / last)
221+ os.copy(mill.api.BuildCtx.workspaceRoot / ".mill-version", f / last / ".mill-version")
222+ os.write.over(f / last / "mill", os.read(mill.api.BuildCtx.workspaceRoot / "mill"))
223+ os.proc("chmod", "+x", f / last / "mill").call(f / last)
224+ os.move(f / last / "package.mill", f / last / "build.mill")
225+ os.write.over(
226+ f / last / "build.mill",
227+ os.read(f / last / "build.mill")
228+ .replaceAll("package build.*", "package build")
229+ .replaceAll("def moduleDeps =.*", "")
230+ .replaceAll("///", "//|")
231+ .replaceAll("app =>", "")
232+ .replaceFirst(
233+ "object app extends.*\ntrait AppModule extends CrossScalaModule(.*)\\{",
234+ s"object app extends ScalaModule $$1\\{\n def scalaVersion = \"${scala213}\"")
235+ .replaceAll("build.scala3", s"\"${scala3}\"")
236+ .replaceFirst(
237+ "def mvnDeps = Seq\\[Dep\\]\\(",
238+ "def mvnDeps = Seq(\n mvn\"com.lihaoyi::cask:" + releaseTag + "\","
239+ )
240+ )
241+
242+ os.zip(f / s"$last.zip", Seq(f / last))
243+ PathRef(f / s"$last.zip")
244+ }
243245 }
244246}
245247
246- def testExamples() = T.command {
248+ def testExamples() = Task.Command {
247249
248250 for(example <- zippedExamples()){
249251 println("Testing " + example.path.last)
250- val base = T .dest / example.path.baseName
252+ val base = Task .dest / example.path.baseName
251253 os.unzip(example.path, base)
252254 os.perms.set(base / "mill", "rwxrwxrwx")
253255 os.write.over(
254256 base / "build.mill",
255257 os.read(base / "build.mill").replaceAll(
256- "ivy \"com.lihaoyi::cask:.*\"",
257- s"""ivy "com.lihaoyi::cask:${VcsVersion.vcsState().format()}""""
258+ "mvn \"com.lihaoyi::cask:.*\"",
259+ s"""mvn "com.lihaoyi::cask:${VcsVersion.vcsState().format()}""""
258260 )
259261 )
260262 os.proc("./mill", "app.test").call(cwd = base, stdout = os.Inherit)
263+ os.proc("./mill", "shutdown").call(cwd = base, stdout = os.Inherit)
261264 }
262265}
263266
264- def uploadToGithub() = T.command{
265- val vcsState = VcsVersion.vcsState()
267+ def uploadToGithub() = Task.Command {
268+ // Separate this out because the Task.Command macro has bugs when
269+ // interacting with request-scala's implicit conversions
270+ doUploadToGithub(VcsVersion.vcsState(), zippedExamples())
271+ }
272+
273+ def doUploadToGithub(vcsState: VcsVersion.State,
274+ zippedExamples: Seq[PathRef])(implicit ctx: mill.api.TaskCtx) = {
266275
267- val authKey = T .env.apply("AMMONITE_BOT_AUTH_TOKEN")
276+ val authKey = Task .env.apply("AMMONITE_BOT_AUTH_TOKEN")
268277 val releaseTag = vcsState.lastTag.getOrElse("")
269278 val label = vcsState.format()
270279 if (releaseTag == label) {
271280 requests.post(
272281 "https://api.github.com/repos/com-lihaoyi/cask/releases",
273- data = ujson.write(
274- ujson.Obj(
275- "tag_name" -> releaseTag,
276- "name" -> releaseTag
277- )
278- ),
282+ data = ujson.Obj("tag_name" -> releaseTag, "name" -> releaseTag),
279283 headers = Seq("Authorization" -> s"token $authKey")
280284 )
281285 }
282286
283- for(example <- zippedExamples()){
284-
285- upload.apply(example.path, releaseTag, example.path.last, authKey)
287+ for(example <- zippedExamples){
288+ ci.upload(example.path, releaseTag, example.path.last, authKey)
286289 }
287290}
0 commit comments