Repository: pantsbuild/pants

Issue:
BSP failure when downlading Scala 3 artifacts
**Describe the bug**
When using Scala 3 and launching the BSP, IntelliJ fails to resolve and download Scala 3 artifacts with following error message:

```
Resolution error: Error downloading org.scala-lang:scala-compiler:3.3.1
  not found: https://maven-central.storage-download.googleapis.com/maven2/org/scala-lang/scala-compiler/3.3.1/scala-compiler-3.3.1.pom
  not found: https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/3.3.1/scala-compiler-3.3.1.pom
Error downloading org.scala-lang:scala-library:3.3.1
  not found: https://maven-central.storage-download.googleapis.com/maven2/org/scala-lang/scala-library/3.3.1/scala-library-3.3.1.pom
  not found: https://repo1.maven.org/maven2/org/scala-lang/scala-library/3.3.1/scala-library-3.3.1.pom
```

This is down to referencing the wrong Scala 3 artifacts, as for Scala 3, the right artifact names are `scala3-library_3` and `scala3-compiler_3`.

**Pants version**
2.18.0rc5

**OS**
both

**Additional info**
N/A



Discussion:

Resolving patch:
diff --git a/src/python/pants/backend/scala/bsp/rules.py b/src/python/pants/backend/scala/bsp/rules.py
--- a/src/python/pants/backend/scala/bsp/rules.py
+++ b/src/python/pants/backend/scala/bsp/rules.py
@@ -21,6 +21,10 @@
 )
 from pants.backend.scala.subsystems.scala import ScalaSubsystem
 from pants.backend.scala.target_types import ScalaFieldSet, ScalaSourceField
+from pants.backend.scala.util_rules.versions import (
+    ScalaArtifactsForVersionRequest,
+    ScalaArtifactsForVersionResult,
+)
 from pants.base.build_root import BuildRoot
 from pants.bsp.protocol import BSPHandlerMapping
 from pants.bsp.spec.base import BuildTargetIdentifier
@@ -148,22 +152,15 @@ async def collect_thirdparty_modules(
 
 
 async def _materialize_scala_runtime_jars(scala_version: str) -> Snapshot:
+    scala_artifacts = await Get(
+        ScalaArtifactsForVersionResult, ScalaArtifactsForVersionRequest(scala_version)
+    )
+
     tool_classpath = await Get(
         ToolClasspath,
         ToolClasspathRequest(
             artifact_requirements=ArtifactRequirements.from_coordinates(
-                [
-                    Coordinate(
-                        group="org.scala-lang",
-                        artifact="scala-compiler",
-                        version=scala_version,
-                    ),
-                    Coordinate(
-                        group="org.scala-lang",
-                        artifact="scala-library",
-                        version=scala_version,
-                    ),
-                ]
+                scala_artifacts.all_coordinates
             ),
         ),
     )
@@ -278,11 +275,17 @@ async def bsp_resolve_scala_metadata(
         java_version=f"1.{jdk.jre_major_version}",
     )
 
+    scala_version_parts = scala_version.split(".")
+    scala_binary_version = (
+        ".".join(scala_version_parts[0:2])
+        if int(scala_version_parts[0]) < 3
+        else scala_version_parts[0]
+    )
     return BSPBuildTargetsMetadataResult(
         metadata=ScalaBuildTarget(
             scala_organization="org.scala-lang",
             scala_version=scala_version,
-            scala_binary_version=".".join(scala_version.split(".")[0:2]),
+            scala_binary_version=scala_binary_version,
             platform=ScalaPlatform.JVM,
             jars=scala_jar_uris,
             jvm_build_target=jvm_build_target,


Test patch: