From 9c11e43b8eb4791fa01466bbff22e8bbb8b92007 Mon Sep 17 00:00:00 2001 From: george-wilson-rea <106576487+george-wilson-rea@users.noreply.github.com> Date: Tue, 28 May 2024 15:58:39 +1000 Subject: [PATCH] feat(sbt): Support Scala 3 dependency resolution (#29291) Co-authored-by: Rhys Arkins <rhys@arkins.net> --- lib/modules/manager/sbt/extract.spec.ts | 20 ++++++++++++++++++++ lib/modules/manager/sbt/extract.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/modules/manager/sbt/extract.spec.ts b/lib/modules/manager/sbt/extract.spec.ts index 98f919b21f..624847a609 100644 --- a/lib/modules/manager/sbt/extract.spec.ts +++ b/lib/modules/manager/sbt/extract.spec.ts @@ -243,6 +243,26 @@ describe('modules/manager/sbt/extract', () => { }); }); + it('extracts deps correctly when dealing with scala 3', () => { + const content = ` + scalaVersion := "3.3.4" + libraryDependencies += "org.example" %% "bar" % "0.0.5" + `; + + expect(extractPackageFile(content)).toMatchObject({ + deps: [ + { + packageName: 'org.scala-lang:scala3-library_3', + currentValue: '3.3.4', + }, + { + packageName: 'org.example:bar_3', + currentValue: '0.0.5', + }, + ], + }); + }); + it('extracts deps when scala version is defined in a variable with ThisBuild scope', () => { const content = ` val ScalaVersion = "2.12.10" diff --git a/lib/modules/manager/sbt/extract.ts b/lib/modules/manager/sbt/extract.ts index 42b2293af4..812fde85ce 100644 --- a/lib/modules/manager/sbt/extract.ts +++ b/lib/modules/manager/sbt/extract.ts @@ -201,12 +201,16 @@ function depHandler(ctx: Ctx): Ctx { delete ctx.variableName; const depName = `${groupId!}:${artifactId!}`; + const isScala3 = scalaVersion?.[0] === '3'; + const scalaVersionForPackageName = isScala3 ? '3' : scalaVersion; const dep: PackageDependency = { datasource: SbtPackageDatasource.id, depName, packageName: - scalaVersion && useScalaVersion ? `${depName}_${scalaVersion}` : depName, + scalaVersionForPackageName && useScalaVersion + ? `${depName}_${scalaVersionForPackageName}` + : depName, currentValue, }; -- GitLab