Skip to content

Commit a865197

Browse files
authored
Port to Scala 2.13 (#133)
1 parent 2b881ee commit a865197

File tree

7 files changed

+63
-9
lines changed

7 files changed

+63
-9
lines changed

.github/workflows/scala.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
scala:
19-
- 2.10.7
20-
- 2.11.12
21-
- 2.12.11
18+
include:
19+
- scala: 2.11.12
20+
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
21+
- scala: 2.12.11
22+
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
23+
- scala: 2.13.4
24+
sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x
25+
- scala: 2.10.7
26+
- scala: 2.11.12
27+
- scala: 2.12.11
28+
- scala: 2.13.4
2229

2330
steps:
2431
- uses: actions/checkout@v3

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ fork in Global in compile := true
99

1010
description in ThisBuild := "A collection of Scala language extension for specific domains."
1111

12-
lazy val each = crossProject.crossType(CrossType.Pure)
12+
lazy val each = sbtcrossproject.CrossPlugin.autoImport.crossProject
13+
.crossType(sbtcrossproject.CrossPlugin.autoImport.CrossType.Pure)
1314

1415
lazy val eachJVM = each.jvm
1516

each/build.sbt.shared

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@ libraryDependencies ++= {
1616
}
1717
}
1818

19-
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
19+
libraryDependencies ++= PartialFunction.condOpt(VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("<2.13"))) {
20+
case true =>
21+
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
22+
}
23+
24+
scalacOptions ++= PartialFunction.condOpt(scalaBinaryVersion.value) {
25+
case "2.13" =>
26+
"-Ymacro-annotations"
27+
}
2028

2129
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
2230

23-
libraryDependencies += "com.thoughtworks.sde" %%% "core" % "3.3.2"
31+
libraryDependencies += {
32+
if (scalaBinaryVersion.value == "2.10") {
33+
"com.thoughtworks.sde" %%% "core" % "3.3.2"
34+
} else {
35+
"com.thoughtworks.sde" %%% "core" % "3.3.4"
36+
}
37+
}
2438

2539
libraryDependencies += "com.thoughtworks.sde" %%% "comprehension-monad" % "3.3.2"
2640

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.thoughtworks.each
2+
3+
import scala.annotation.StaticAnnotation
4+
5+
private[each] object macrocompat {
6+
class bundle extends StaticAnnotation
7+
}

each/src/test/scala/com/thoughtworks/each/MonadicTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ class MonadicTest {
318318
} catch {
319319
case e: Exception => {
320320
count += 1
321-
100
321+
// FIXME: compile time error on Scala 2.13 if removing `: Int`
322+
100: Int
322323
}
323324
} finally {
324325
count += 1

project/plugins.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ addSbtPlugin(
44

55
addSbtPlugin("com.thoughtworks.sbt-scala-js-map" % "sbt-scala-js-map" % "4.0.0")
66

7-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32")
7+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.33")
88

99
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.17")
1010

@@ -15,3 +15,5 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
1515
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2")
1616

1717
addSbtPlugin("com.thoughtworks.example" % "sbt-example" % "9.2.1")
18+
19+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")

project/plugins.sbt.scala-js.1.x

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// An optional sbt file to replace Scala.js 1.0 with 0.6
2+
dependencyOverrides += Defaults.sbtPluginExtra(
3+
"org.scala-js" % "sbt-scalajs" % "1.0.1",
4+
sbtBinaryVersion.value,
5+
scalaBinaryVersion.value,
6+
)
7+
8+
Compile / sourceGenerators += Def.task {
9+
val file = (Compile / sourceManaged).value / "SkipPublishForNonScalaJSProjects.scala"
10+
IO.write(file, """
11+
import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
12+
import sbtcrossproject.CrossPlugin.autoImport._
13+
import sbt._, Keys._
14+
object SkipPublishForNonScalaJSProjects extends AutoPlugin {
15+
override def trigger = allRequirements
16+
override def projectSettings = Seq(
17+
publish / skip := crossProjectPlatform.value != JSPlatform
18+
)
19+
}
20+
""")
21+
Seq(file)
22+
}.taskValue

0 commit comments

Comments
 (0)