From 54b5f6de43d43eb9eff1de57eca2fb733f218b61 Mon Sep 17 00:00:00 2001
From: Moritz Hedtke <Moritz.Hedtke@t-online.de>
Date: Sat, 7 Jan 2023 22:28:12 +0100
Subject: [PATCH] feat(manager/sbt): Implement %%% dependency specifiers
 (#19656)

---
 lib/modules/manager/sbt/__fixtures__/sample.sbt   |  1 +
 .../sbt/__snapshots__/extract.spec.ts.snap        | 15 +++++++++++++++
 lib/modules/manager/sbt/extract.spec.ts           |  1 +
 lib/modules/manager/sbt/extract.ts                |  9 ++++++++-
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/modules/manager/sbt/__fixtures__/sample.sbt b/lib/modules/manager/sbt/__fixtures__/sample.sbt
index 9c82f1186c..3d60943cf8 100644
--- a/lib/modules/manager/sbt/__fixtures__/sample.sbt
+++ b/lib/modules/manager/sbt/__fixtures__/sample.sbt
@@ -19,6 +19,7 @@ dependencyOverrides ++= {
 
   Seq(
     groupIdExample %% "quuz" % "0.0.6" % "test",           // comment
+    groupIdExample %%% "abc" % "0.0.42" % "test",          // comment
     "org.example" % artifactIdExample % "0.0.7" % Provided // comment
     ,"org.example" % "grault" % versionExample % Test,     // comment
   )
diff --git a/lib/modules/manager/sbt/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/sbt/__snapshots__/extract.spec.ts.snap
index fc4242ac84..da6fe24303 100644
--- a/lib/modules/manager/sbt/__snapshots__/extract.spec.ts.snap
+++ b/lib/modules/manager/sbt/__snapshots__/extract.spec.ts.snap
@@ -222,6 +222,21 @@ exports[`modules/manager/sbt/extract extractPackageFile() extracts deps for gene
         "https://example.com/repos/5/",
       ],
     },
+    {
+      "currentValue": "0.0.42",
+      "datasource": "sbt-package",
+      "depName": "org.example:abc",
+      "depType": "test",
+      "packageName": "org.example:abc_2.9.10",
+      "registryUrls": [
+        "https://repo.maven.apache.org/maven2",
+        "https://example.com/repos/1/",
+        "https://example.com/repos/2/",
+        "https://example.com/repos/3/",
+        "https://example.com/repos/4/",
+        "https://example.com/repos/5/",
+      ],
+    },
     {
       "currentValue": "0.0.7",
       "datasource": "sbt-package",
diff --git a/lib/modules/manager/sbt/extract.spec.ts b/lib/modules/manager/sbt/extract.spec.ts
index 72aa378bc1..da3c83ae8c 100644
--- a/lib/modules/manager/sbt/extract.spec.ts
+++ b/lib/modules/manager/sbt/extract.spec.ts
@@ -54,6 +54,7 @@ describe('modules/manager/sbt/extract', () => {
           },
           { packageName: 'org.example:quux', currentValue: '0.0.5' },
           { packageName: 'org.example:quuz_2.9.10', currentValue: '0.0.6' },
+          { packageName: 'org.example:abc_2.9.10', currentValue: '0.0.42' },
           { packageName: 'org.example:corge', currentValue: '0.0.7' },
           { packageName: 'org.example:grault', currentValue: '0.0.8' },
           { packageName: 'org.example:waldo', currentValue: '0.0.9' },
diff --git a/lib/modules/manager/sbt/extract.ts b/lib/modules/manager/sbt/extract.ts
index 1996f299cb..bf4478d60c 100644
--- a/lib/modules/manager/sbt/extract.ts
+++ b/lib/modules/manager/sbt/extract.ts
@@ -149,6 +149,13 @@ const versionedDependencyMatch = groupIdMatch
   .op('%')
   .join(versionMatch);
 
+const crossDependencyMatch = groupIdMatch
+  .op('%%%')
+  .join(artifactIdMatch)
+  .handler((ctx) => ({ ...ctx, useScalaVersion: true }))
+  .op('%')
+  .join(versionMatch);
+
 function depHandler(ctx: Ctx): Ctx {
   const {
     scalaVersion,
@@ -200,7 +207,7 @@ function depTypeHandler(ctx: Ctx, { value: depType }: { value: string }): Ctx {
 
 const sbtPackageMatch = q
   .opt<Ctx>(q.opt(q.sym<Ctx>('lazy')).sym('val').sym().op('='))
-  .alt(simpleDependencyMatch, versionedDependencyMatch)
+  .alt(crossDependencyMatch, simpleDependencyMatch, versionedDependencyMatch)
   .opt(
     q.alt<Ctx>(
       q.sym<Ctx>('classifier').str(depTypeHandler),
-- 
GitLab