Skip to content

Commit 89326be

Browse files
committed
Part 13 - fix contrib.playlib resolution of twirl and router worker
1 parent c862887 commit 89326be

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

contrib/playlib/src/mill/playlib/PlayModule.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ trait PlayApiModule extends Dependencies with Router with Server {
2626

2727
}
2828
trait PlayModule extends PlayApiModule with Static with Twirl {
29+
override def twirlScalaVersion: T[String] = Task {
30+
if scalaVersion().startsWith("2.13.") then
31+
// TODO: This determines which version of `twirl-compiler` library
32+
// will be used to source-generate scala files from twirl sources,
33+
// which will then be further compiled by the Scala compiler corresponding to `scalaVersion`.
34+
// The Scala 3 version of `twirl-compiler` generates code that
35+
// is not source compatible with scala 2 - so we should downgrade it to 2.13 version.
36+
mill.main.BuildInfo.workerScalaVersion213
37+
else
38+
super.twirlScalaVersion()
39+
}
40+
2941
override def twirlVersion: T[String] = Task {
3042
playMinorVersion() match {
3143
case "2.6" => "1.3.16"

contrib/playlib/src/mill/playlib/RouterModule.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ trait RouterModule extends ScalaModule with Version {
8080
repositoriesTask(),
8181
artifactSuffix = playMinorVersion() match {
8282
case "2.6" => "_2.12"
83-
case _ => "_2.13"
83+
case "2.7" | "2.8" => "_2.13"
84+
case _ => "_3"
8485
}
8586
)
8687
}

contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ object RouterModuleTests extends TestSuite with PlayTestSuite {
7171
val eitherResult = eval.apply(project.compileRouter)
7272
val Left(Failure(message, x)) = eitherResult
7373
val playExpectedMessage =
74-
if (playVersion.startsWith("2.6.")) {
74+
if !playVersion.startsWith("2.7.") && !playVersion.startsWith("2.8.") then {
7575
"HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected"
7676
} else {
7777
"end of input expected"
@@ -98,7 +98,7 @@ object RouterModuleTests extends TestSuite with PlayTestSuite {
9898
val eitherResult = eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter)
9999
val Left(Failure(message, x)) = eitherResult
100100
val playExpectedMessage =
101-
if (playVersion.startsWith("2.6.")) {
101+
if !playVersion.startsWith("2.7.") && !playVersion.startsWith("2.8.") then {
102102
"HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected"
103103
} else {
104104
"end of input expected"

contrib/twirllib/src/mill/twirllib/TwirlModule.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ trait TwirlModule extends mill.Module { twirlModule =>
2020
*/
2121
def twirlScalaVersion: T[String] = Task {
2222
twirlVersion() match {
23-
case s"1.$minor.$_" if minor.toIntOption.exists(_ < 4) => BuildInfo.workerScalaVersion212
23+
case s"1.$minor.$_" if minor.toIntOption.exists(_ < 6) =>
24+
if minor.toIntOption.exists(_ < 4) then BuildInfo.workerScalaVersion212
25+
else BuildInfo.workerScalaVersion213
2426
case _ => BuildInfo.scalaVersion
2527
}
2628
}

contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import utest.{TestSuite, Tests, assert, _}
77

88
trait HelloWorldTests extends TestSuite {
99
val testTwirlVersion: String
10+
val wildcard: String
1011

1112
trait HelloWorldModule extends mill.twirllib.TwirlModule {
1213
def twirlVersion = testTwirlVersion
@@ -39,17 +40,17 @@ trait HelloWorldTests extends TestSuite {
3940
)
4041

4142
def expectedDefaultImports: Seq[String] = Seq(
42-
"import _root_.play.twirl.api.TwirlFeatureImports._",
43-
"import _root_.play.twirl.api.TwirlHelperImports._",
43+
s"import _root_.play.twirl.api.TwirlFeatureImports.$wildcard",
44+
s"import _root_.play.twirl.api.TwirlHelperImports.$wildcard",
4445
"import _root_.play.twirl.api.Html",
4546
"import _root_.play.twirl.api.JavaScript",
4647
"import _root_.play.twirl.api.Txt",
4748
"import _root_.play.twirl.api.Xml"
4849
)
4950

5051
def testAdditionalImports: Seq[String] = Seq(
51-
"mill.twirl.test.AdditionalImport1._",
52-
"mill.twirl.test.AdditionalImport2._"
52+
s"mill.twirl.test.AdditionalImport1.$wildcard",
53+
s"mill.twirl.test.AdditionalImport2.$wildcard"
5354
)
5455

5556
def testConstructorAnnotations = Seq(
@@ -159,13 +160,17 @@ trait HelloWorldTests extends TestSuite {
159160

160161
object HelloWorldTests1_3 extends HelloWorldTests {
161162
override val testTwirlVersion = "1.3.16"
163+
override val wildcard = "_"
162164
}
163165
object HelloWorldTests1_5 extends HelloWorldTests {
164166
override val testTwirlVersion = "1.5.2"
167+
override val wildcard = "_"
165168
}
166169
object HelloWorldTests1_6 extends HelloWorldTests {
167170
override val testTwirlVersion = "1.6.2"
171+
override val wildcard = "*"
168172
}
169173
object HelloWorldTests2_0 extends HelloWorldTests {
170174
override val testTwirlVersion = "2.0.1"
175+
override val wildcard = "*"
171176
}

main/package.mill

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ object `package` extends RootModule with build.MillStableScalaModule with BuildI
2525

2626
def buildInfoMembers = Seq(
2727
BuildInfo.Value("scalaVersion", scalaVersion(), "Scala version used to compile mill core."),
28+
BuildInfo.Value(
29+
"workerScalaVersion213",
30+
build.Deps.scala2Version,
31+
"Scala 2.13 version used by some workers."
32+
),
2833
BuildInfo.Value(
2934
"workerScalaVersion212",
3035
build.Deps.workerScalaVersion212,

0 commit comments

Comments
 (0)