Skip to content

Commit 5f19ac3

Browse files
Dotty SBT plugin updated to work with Scala 3
1 parent 66f17bb commit 5f19ac3

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object DottyPlugin extends AutoPlugin {
3535

3636
// get latest nightly version from maven
3737
def fetchSource(version: String): (scala.io.BufferedSource, String) =
38-
try Source.fromURL(s"https://repo1.maven.org/maven2/ch/epfl/lamp/dotty_$version/maven-metadata.xml") -> version
38+
try Source.fromURL(s"https://repo1.maven.org/maven2/org/scala-lang/scala3_$version/maven-metadata.xml") -> version
3939
catch { case t: java.io.FileNotFoundException =>
4040
val major :: minor :: Nil = version.split('.').toList
4141
if (minor.toInt <= 0) throw t
@@ -92,7 +92,7 @@ object DottyPlugin extends AutoPlugin {
9292
*/
9393
def withDottyCompat(scalaVersion: String): ModuleID = {
9494
val name = moduleID.name
95-
if (name != "dotty" && name != "dotty-library" && name != "dotty-compiler")
95+
if (name != "scala3" && name != "scala3-library" && name != "scala3-compiler")
9696
moduleID.crossVersion match {
9797
case binary: librarymanagement.Binary =>
9898
val compatVersion =
@@ -167,6 +167,14 @@ object DottyPlugin extends AutoPlugin {
167167

168168
// https://github.com/sbt/sbt/issues/3110
169169
val Def = sbt.Def
170+
171+
private def scala3Artefact(version: String, name: String) =
172+
if (version.startsWith("0.")) s"dotty-$name"
173+
else if (version.startsWith("3.")) s"scala3-$name"
174+
else throw new RuntimeException(
175+
s"Cannot construct a Scala 3 artefact name $name for a non-Scala3 " +
176+
s"scala version ${version}")
177+
170178
override def projectSettings: Seq[Setting[_]] = {
171179
Seq(
172180
isDotty := scalaVersion.value.startsWith("0.") || scalaVersion.value.startsWith("3."),
@@ -195,8 +203,10 @@ object DottyPlugin extends AutoPlugin {
195203
},
196204

197205
scalaOrganization := {
198-
if (isDotty.value)
206+
if (scalaVersion.value.startsWith("0."))
199207
"ch.epfl.lamp"
208+
else if (scalaVersion.value.startsWith("3."))
209+
"org.scala-lang"
200210
else
201211
scalaOrganization.value
202212
},
@@ -212,14 +222,14 @@ object DottyPlugin extends AutoPlugin {
212222
scalaCompilerBridgeBinaryJar := Def.settingDyn {
213223
if (isDotty.value) Def.task {
214224
val updateReport = fetchArtifactsOf(
215-
scalaOrganization.value % "dotty-sbt-bridge" % scalaVersion.value,
225+
scalaOrganization.value % scala3Artefact(scalaVersion.value, "sbt-bridge") % scalaVersion.value,
216226
dependencyResolution.value,
217227
scalaModuleInfo.value,
218228
updateConfiguration.value,
219229
(unresolvedWarningConfiguration in update).value,
220230
streams.value.log,
221231
)
222-
Option(getJar(updateReport, scalaOrganization.value, "dotty-sbt-bridge", scalaVersion.value))
232+
Option(getJar(updateReport, scalaOrganization.value, scala3Artefact(scalaVersion.value, "sbt-bridge"), scalaVersion.value))
223233
}
224234
else Def.task {
225235
None: Option[File]
@@ -228,7 +238,7 @@ object DottyPlugin extends AutoPlugin {
228238

229239
// Needed for RCs publishing
230240
scalaBinaryVersion := {
231-
if (isDotty.value)
241+
if (scalaVersion.value.startsWith("0."))
232242
scalaVersion.value.split("\\.").take(2).mkString(".")
233243
else
234244
scalaBinaryVersion.value
@@ -326,15 +336,15 @@ object DottyPlugin extends AutoPlugin {
326336
// ... instead, we'll fetch the compiler and its dependencies ourselves.
327337
scalaInstance := Def.taskDyn {
328338
if (isDotty.value)
329-
dottyScalaInstanceTask("dotty-compiler")
339+
dottyScalaInstanceTask(scala3Artefact(scalaVersion.value, "compiler"))
330340
else
331341
Def.valueStrict { scalaInstance.taskValue }
332342
}.value,
333343

334344
// We need more stuff on the classpath to run the `doc` task.
335345
scalaInstance in doc := Def.taskDyn {
336346
if (isDotty.value)
337-
dottyScalaInstanceTask("dotty-doc")
347+
dottyScalaInstanceTask(scala3Artefact(scalaVersion.value, "doc"))
338348
else
339349
Def.valueStrict { (scalaInstance in doc).taskValue }
340350
}.value,
@@ -343,8 +353,8 @@ object DottyPlugin extends AutoPlugin {
343353
libraryDependencies ++= {
344354
if (isDotty.value && autoScalaLibrary.value) {
345355
val name =
346-
if (isDottyJS.value) "dotty-library_sjs1"
347-
else "dotty-library"
356+
if (isDottyJS.value) scala3Artefact(scalaVersion.value, "library_sjs1")
357+
else scala3Artefact(scalaVersion.value, "library")
348358
Seq(scalaOrganization.value %% name % scalaVersion.value)
349359
} else
350360
Seq()
@@ -479,9 +489,9 @@ object DottyPlugin extends AutoPlugin {
479489
val scalaLibraryJar = getJar(updateReport,
480490
"org.scala-lang", "scala-library", revision = AllPassFilter)
481491
val dottyLibraryJar = getJar(updateReport,
482-
scalaOrganization.value, s"dotty-library_${scalaBinaryVersion.value}", scalaVersion.value)
492+
scalaOrganization.value, scala3Artefact(scalaVersion.value, s"library_${scalaBinaryVersion.value}"), scalaVersion.value)
483493
val compilerJar = getJar(updateReport,
484-
scalaOrganization.value, s"dotty-compiler_${scalaBinaryVersion.value}", scalaVersion.value)
494+
scalaOrganization.value, scala3Artefact(scalaVersion.value, s"compiler_${scalaBinaryVersion.value}"), scalaVersion.value)
485495
val allJars =
486496
getJars(updateReport, AllPassFilter, AllPassFilter, AllPassFilter)
487497

0 commit comments

Comments
 (0)