We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[scalac]: Failing to load kind-projector plugin when there is more than one global scalac plugins
**Describe the bug**
Spotted an odd behaviour when using more than one global scalac plugins, in which during `./pants check ...` command, Pantsbuild would complain about not being able to find/load one of them.

Project structure, is a follows:
`3rdparty/jvm/kind-projector/BUILD`:
```python
jvm_artifact(
    name="jar",
    group="org.typelevel",
    artifact="kind-projector_2.13.6",
    version="0.13+",
    compatible_resolves=["jvm_default"],
)

scalac_plugin(
    name="plugin",
    plugin_name="kind-projector",
    artifact="//3rdparty/jvm/kind-projector:jar",
)
```

`3rdparty/jvm/bm4/BUILD`:
```python
jvm_artifact(
  name="jar",
  group="com.olegpy",
  artifact="better-monadic-for_2.13",
  version="0.3+",
  compatible_resolves=['jvm_default'],
)

scalac_plugin(
    name="plugin",
    plugin_name="bm4",
    artifact="//3rdparty/jvm/bm4:jar",
)
```

`pants.toml`:
```toml
[scalac]
args = ['-Ymacro-annotations']
plugins_global = [
  "//3rdparty/jvm/kind-projector:plugin",
  "//3rdparty/jvm/bm4:plugin",
]
plugins_global_lockfile = "3rdparty/jvm/global_plugins.lock"
```

`src/main/scala/KindProjectorTest.scala`:
```scala
trait Functor[F[_]] {
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

object KindProjectorTest {
  implicit def eitherFunctor[E]: Functor[Either[E, *]] = new Functor[Either[E, *]] {
    def map[A, B](fa: Either[E, A])(f: A => B): Either[E, B] = {
        fa match {
          case Left(e) => Left(e)
          case Right(a) => Right(f(a))
        }
      }
    }
  }
}
```

`src/main/scala/BUILD`:
```python
scala_sources(sources=["*.scala"])
```

When running `./pants check ::` in the root folder of that project, pants stdout spits out the error:
```
13:59:52.32 [ERROR] Completed: Compile with scalac - src/main/scala/KindProjectorTest.scala failed (exit code 1).
1 error

error: Missing required plugin: kind-projector
```

If the scalac argument `-Xplugin-list` is added to scalac's globals in `pants.toml`, the error goes away.

**Pants version**
2.9.0rc1

**OS**
MacOS

**Additional info**
When running `./pants dependencies ::`, pants correctly shows a dependency on `3rdparty/jvm/kind-projector:jar` but it doesn't show any dependency on `3rdparty/jvm/bm4:jar`, even though both are configured as global plugins (not sure if related).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/python/pants/backend/scala/compile/scalac_plugins.py`
Content:
```
1 # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2 # Licensed under the Apache License, Version 2.0 (see LICENSE).
3 
4 from __future__ import annotations
5 
6 from dataclasses import dataclass
7 from typing import Iterator, cast
8 
9 from pants.backend.scala.subsystems.scalac import Scalac
10 from pants.backend.scala.target_types import (
11     ScalacPluginArtifactField,
12     ScalacPluginNameField,
13     ScalacPluginTarget,
14 )
15 from pants.build_graph.address import AddressInput
16 from pants.engine.rules import Get, MultiGet, collect_rules, rule
17 from pants.engine.target import WrappedTarget
18 from pants.engine.unions import UnionRule
19 from pants.jvm.resolve.coursier_fetch import (
20     CoursierResolvedLockfile,
21     MaterializedClasspath,
22     MaterializedClasspathRequest,
23 )
24 from pants.jvm.resolve.jvm_tool import JvmToolLockfileRequest, JvmToolLockfileSentinel
25 from pants.jvm.resolve.jvm_tool import rules as jvm_tool_rules
26 from pants.util.ordered_set import FrozenOrderedSet
27 from pants.util.strutil import bullet_list
28 
29 
30 @dataclass(frozen=True)
31 class _LoadedGlobalScalacPlugins:
32     names: tuple[str, ...]
33     artifact_address_inputs: tuple[str, ...]
34 
35 
36 @rule
37 async def parse_global_scalac_plugins(scalac_plugins: Scalac) -> _LoadedGlobalScalacPlugins:
38     targets = await MultiGet(
39         Get(WrappedTarget, AddressInput, AddressInput.parse(ai))
40         for ai in scalac_plugins.plugins_global
41     )
42 
43     artifact_address_inputs = []
44     names = []
45     invalid_targets = []
46     for wrapped_target in targets:
47         target = wrapped_target.target
48         if target.has_field(ScalacPluginArtifactField):
49             artifact_address_inputs.append(cast(str, target[ScalacPluginArtifactField].value))
50             names.append(target.get(ScalacPluginNameField).value or target.address.target_name)
51         else:
52             invalid_targets.append(target)
53 
54     if invalid_targets:
55         raise ValueError(
56             f"The `[{Scalac.options_scope}].global` option accepts only "
57             f"`{ScalacPluginTarget.alias}` targets, but got:\n\n"
58             f"{bullet_list(type(t).alias for t in invalid_targets)}"
59         )
60 
61     return _LoadedGlobalScalacPlugins(
62         names=tuple(names), artifact_address_inputs=tuple(artifact_address_inputs)
63     )
64 
65 
66 class GlobalScalacPluginsToolLockfileSentinel(JvmToolLockfileSentinel):
67     resolve_name = "scalac-plugins"
68 
69 
70 @rule
71 def generate_global_scalac_plugins_lockfile_request(
72     _: GlobalScalacPluginsToolLockfileSentinel,
73     loaded_global_plugins: _LoadedGlobalScalacPlugins,
74     scalac_plugins: Scalac,
75 ) -> JvmToolLockfileRequest:
76     return JvmToolLockfileRequest(
77         artifact_inputs=FrozenOrderedSet(loaded_global_plugins.artifact_address_inputs),
78         resolve_name="scalac-plugins",
79         lockfile_dest=scalac_plugins.plugins_global_lockfile,
80     )
81 
82 
83 @dataclass(frozen=True)
84 class GlobalScalacPlugins:
85     names: tuple[str, ...]
86     classpath: MaterializedClasspath
87 
88     def args(self, prefix: str | None = None) -> Iterator[str]:
89         scalac_plugins_arg = ":".join(self.classpath.classpath_entries(prefix))
90         if scalac_plugins_arg:
91             yield f"-Xplugin:{scalac_plugins_arg}"
92         for name in self.names:
93             yield f"-Xplugin-require:{name}"
94 
95 
96 @rule
97 async def global_scalac_plugins(
98     loaded_global_plugins: _LoadedGlobalScalacPlugins,
99 ) -> GlobalScalacPlugins:
100 
101     lockfile = await Get(CoursierResolvedLockfile, GlobalScalacPluginsToolLockfileSentinel())
102     classpath = await Get(
103         MaterializedClasspath,
104         MaterializedClasspathRequest(
105             prefix="__scalac_plugin_cp",
106             lockfiles=(lockfile,),
107         ),
108     )
109     return GlobalScalacPlugins(loaded_global_plugins.names, classpath)
110 
111 
112 def rules():
113     return (
114         *collect_rules(),
115         *jvm_tool_rules(),
116         UnionRule(JvmToolLockfileSentinel, GlobalScalacPluginsToolLockfileSentinel),
117     )
118
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/python/pants/backend/scala/compile/scalac_plugins.py b/src/python/pants/backend/scala/compile/scalac_plugins.py
--- a/src/python/pants/backend/scala/compile/scalac_plugins.py
+++ b/src/python/pants/backend/scala/compile/scalac_plugins.py
@@ -86,9 +86,8 @@
     classpath: MaterializedClasspath
 
     def args(self, prefix: str | None = None) -> Iterator[str]:
-        scalac_plugins_arg = ":".join(self.classpath.classpath_entries(prefix))
-        if scalac_plugins_arg:
-            yield f"-Xplugin:{scalac_plugins_arg}"
+        for scalac_plugin_path in self.classpath.classpath_entries(prefix):
+            yield f"-Xplugin:{scalac_plugin_path}"
         for name in self.names:
             yield f"-Xplugin-require:{name}"

{"golden_diff": "diff --git a/src/python/pants/backend/scala/compile/scalac_plugins.py b/src/python/pants/backend/scala/compile/scalac_plugins.py\n--- a/src/python/pants/backend/scala/compile/scalac_plugins.py\n+++ b/src/python/pants/backend/scala/compile/scalac_plugins.py\n@@ -86,9 +86,8 @@\n     classpath: MaterializedClasspath\n \n     def args(self, prefix: str | None = None) -> Iterator[str]:\n-        scalac_plugins_arg = \":\".join(self.classpath.classpath_entries(prefix))\n-        if scalac_plugins_arg:\n-            yield f\"-Xplugin:{scalac_plugins_arg}\"\n+        for scalac_plugin_path in self.classpath.classpath_entries(prefix):\n+            yield f\"-Xplugin:{scalac_plugin_path}\"\n         for name in self.names:\n             yield f\"-Xplugin-require:{name}\"\n", "issue": "[scalac]: Failing to load kind-projector plugin when there is more than one global scalac plugins\n**Describe the bug**\r\nSpotted an odd behaviour when using more than one global scalac plugins, in which during `./pants check ...` command, Pantsbuild would complain about not being able to find/load one of them.\r\n\r\nProject structure, is a follows:\r\n`3rdparty/jvm/kind-projector/BUILD`:\r\n```python\r\njvm_artifact(\r\n    name=\"jar\",\r\n    group=\"org.typelevel\",\r\n    artifact=\"kind-projector_2.13.6\",\r\n    version=\"0.13+\",\r\n    compatible_resolves=[\"jvm_default\"],\r\n)\r\n\r\nscalac_plugin(\r\n    name=\"plugin\",\r\n    plugin_name=\"kind-projector\",\r\n    artifact=\"//3rdparty/jvm/kind-projector:jar\",\r\n)\r\n```\r\n\r\n`3rdparty/jvm/bm4/BUILD`:\r\n```python\r\njvm_artifact(\r\n  name=\"jar\",\r\n  group=\"com.olegpy\",\r\n  artifact=\"better-monadic-for_2.13\",\r\n  version=\"0.3+\",\r\n  compatible_resolves=['jvm_default'],\r\n)\r\n\r\nscalac_plugin(\r\n    name=\"plugin\",\r\n    plugin_name=\"bm4\",\r\n    artifact=\"//3rdparty/jvm/bm4:jar\",\r\n)\r\n```\r\n\r\n`pants.toml`:\r\n```toml\r\n[scalac]\r\nargs = ['-Ymacro-annotations']\r\nplugins_global = [\r\n  \"//3rdparty/jvm/kind-projector:plugin\",\r\n  \"//3rdparty/jvm/bm4:plugin\",\r\n]\r\nplugins_global_lockfile = \"3rdparty/jvm/global_plugins.lock\"\r\n```\r\n\r\n`src/main/scala/KindProjectorTest.scala`:\r\n```scala\r\ntrait Functor[F[_]] {\r\n  def map[A, B](fa: F[A])(f: A => B): F[B]\r\n}\r\n\r\nobject KindProjectorTest {\r\n  implicit def eitherFunctor[E]: Functor[Either[E, *]] = new Functor[Either[E, *]] {\r\n    def map[A, B](fa: Either[E, A])(f: A => B): Either[E, B] = {\r\n        fa match {\r\n          case Left(e) => Left(e)\r\n          case Right(a) => Right(f(a))\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n`src/main/scala/BUILD`:\r\n```python\r\nscala_sources(sources=[\"*.scala\"])\r\n```\r\n\r\nWhen running `./pants check ::` in the root folder of that project, pants stdout spits out the error:\r\n```\r\n13:59:52.32 [ERROR] Completed: Compile with scalac - src/main/scala/KindProjectorTest.scala failed (exit code 1).\r\n1 error\r\n\r\nerror: Missing required plugin: kind-projector\r\n```\r\n\r\nIf the scalac argument `-Xplugin-list` is added to scalac's globals in `pants.toml`, the error goes away.\r\n\r\n**Pants version**\r\n2.9.0rc1\r\n\r\n**OS**\r\nMacOS\r\n\r\n**Additional info**\r\nWhen running `./pants dependencies ::`, pants correctly shows a dependency on `3rdparty/jvm/kind-projector:jar` but it doesn't show any dependency on `3rdparty/jvm/bm4:jar`, even though both are configured as global plugins (not sure if related).\r\n\n", "before_files": [{"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass\nfrom typing import Iterator, cast\n\nfrom pants.backend.scala.subsystems.scalac import Scalac\nfrom pants.backend.scala.target_types import (\n    ScalacPluginArtifactField,\n    ScalacPluginNameField,\n    ScalacPluginTarget,\n)\nfrom pants.build_graph.address import AddressInput\nfrom pants.engine.rules import Get, MultiGet, collect_rules, rule\nfrom pants.engine.target import WrappedTarget\nfrom pants.engine.unions import UnionRule\nfrom pants.jvm.resolve.coursier_fetch import (\n    CoursierResolvedLockfile,\n    MaterializedClasspath,\n    MaterializedClasspathRequest,\n)\nfrom pants.jvm.resolve.jvm_tool import JvmToolLockfileRequest, JvmToolLockfileSentinel\nfrom pants.jvm.resolve.jvm_tool import rules as jvm_tool_rules\nfrom pants.util.ordered_set import FrozenOrderedSet\nfrom pants.util.strutil import bullet_list\n\n\n@dataclass(frozen=True)\nclass _LoadedGlobalScalacPlugins:\n    names: tuple[str, ...]\n    artifact_address_inputs: tuple[str, ...]\n\n\n@rule\nasync def parse_global_scalac_plugins(scalac_plugins: Scalac) -> _LoadedGlobalScalacPlugins:\n    targets = await MultiGet(\n        Get(WrappedTarget, AddressInput, AddressInput.parse(ai))\n        for ai in scalac_plugins.plugins_global\n    )\n\n    artifact_address_inputs = []\n    names = []\n    invalid_targets = []\n    for wrapped_target in targets:\n        target = wrapped_target.target\n        if target.has_field(ScalacPluginArtifactField):\n            artifact_address_inputs.append(cast(str, target[ScalacPluginArtifactField].value))\n            names.append(target.get(ScalacPluginNameField).value or target.address.target_name)\n        else:\n            invalid_targets.append(target)\n\n    if invalid_targets:\n        raise ValueError(\n            f\"The `[{Scalac.options_scope}].global` option accepts only \"\n            f\"`{ScalacPluginTarget.alias}` targets, but got:\\n\\n\"\n            f\"{bullet_list(type(t).alias for t in invalid_targets)}\"\n        )\n\n    return _LoadedGlobalScalacPlugins(\n        names=tuple(names), artifact_address_inputs=tuple(artifact_address_inputs)\n    )\n\n\nclass GlobalScalacPluginsToolLockfileSentinel(JvmToolLockfileSentinel):\n    resolve_name = \"scalac-plugins\"\n\n\n@rule\ndef generate_global_scalac_plugins_lockfile_request(\n    _: GlobalScalacPluginsToolLockfileSentinel,\n    loaded_global_plugins: _LoadedGlobalScalacPlugins,\n    scalac_plugins: Scalac,\n) -> JvmToolLockfileRequest:\n    return JvmToolLockfileRequest(\n        artifact_inputs=FrozenOrderedSet(loaded_global_plugins.artifact_address_inputs),\n        resolve_name=\"scalac-plugins\",\n        lockfile_dest=scalac_plugins.plugins_global_lockfile,\n    )\n\n\n@dataclass(frozen=True)\nclass GlobalScalacPlugins:\n    names: tuple[str, ...]\n    classpath: MaterializedClasspath\n\n    def args(self, prefix: str | None = None) -> Iterator[str]:\n        scalac_plugins_arg = \":\".join(self.classpath.classpath_entries(prefix))\n        if scalac_plugins_arg:\n            yield f\"-Xplugin:{scalac_plugins_arg}\"\n        for name in self.names:\n            yield f\"-Xplugin-require:{name}\"\n\n\n@rule\nasync def global_scalac_plugins(\n    loaded_global_plugins: _LoadedGlobalScalacPlugins,\n) -> GlobalScalacPlugins:\n\n    lockfile = await Get(CoursierResolvedLockfile, GlobalScalacPluginsToolLockfileSentinel())\n    classpath = await Get(\n        MaterializedClasspath,\n        MaterializedClasspathRequest(\n            prefix=\"__scalac_plugin_cp\",\n            lockfiles=(lockfile,),\n        ),\n    )\n    return GlobalScalacPlugins(loaded_global_plugins.names, classpath)\n\n\ndef rules():\n    return (\n        *collect_rules(),\n        *jvm_tool_rules(),\n        UnionRule(JvmToolLockfileSentinel, GlobalScalacPluginsToolLockfileSentinel),\n    )\n", "path": "src/python/pants/backend/scala/compile/scalac_plugins.py"}], "after_files": [{"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass\nfrom typing import Iterator, cast\n\nfrom pants.backend.scala.subsystems.scalac import Scalac\nfrom pants.backend.scala.target_types import (\n    ScalacPluginArtifactField,\n    ScalacPluginNameField,\n    ScalacPluginTarget,\n)\nfrom pants.build_graph.address import AddressInput\nfrom pants.engine.rules import Get, MultiGet, collect_rules, rule\nfrom pants.engine.target import WrappedTarget\nfrom pants.engine.unions import UnionRule\nfrom pants.jvm.resolve.coursier_fetch import (\n    CoursierResolvedLockfile,\n    MaterializedClasspath,\n    MaterializedClasspathRequest,\n)\nfrom pants.jvm.resolve.jvm_tool import JvmToolLockfileRequest, JvmToolLockfileSentinel\nfrom pants.jvm.resolve.jvm_tool import rules as jvm_tool_rules\nfrom pants.util.ordered_set import FrozenOrderedSet\nfrom pants.util.strutil import bullet_list\n\n\n@dataclass(frozen=True)\nclass _LoadedGlobalScalacPlugins:\n    names: tuple[str, ...]\n    artifact_address_inputs: tuple[str, ...]\n\n\n@rule\nasync def parse_global_scalac_plugins(scalac_plugins: Scalac) -> _LoadedGlobalScalacPlugins:\n    targets = await MultiGet(\n        Get(WrappedTarget, AddressInput, AddressInput.parse(ai))\n        for ai in scalac_plugins.plugins_global\n    )\n\n    artifact_address_inputs = []\n    names = []\n    invalid_targets = []\n    for wrapped_target in targets:\n        target = wrapped_target.target\n        if target.has_field(ScalacPluginArtifactField):\n            artifact_address_inputs.append(cast(str, target[ScalacPluginArtifactField].value))\n            names.append(target.get(ScalacPluginNameField).value or target.address.target_name)\n        else:\n            invalid_targets.append(target)\n\n    if invalid_targets:\n        raise ValueError(\n            f\"The `[{Scalac.options_scope}].global` option accepts only \"\n            f\"`{ScalacPluginTarget.alias}` targets, but got:\\n\\n\"\n            f\"{bullet_list(type(t).alias for t in invalid_targets)}\"\n        )\n\n    return _LoadedGlobalScalacPlugins(\n        names=tuple(names), artifact_address_inputs=tuple(artifact_address_inputs)\n    )\n\n\nclass GlobalScalacPluginsToolLockfileSentinel(JvmToolLockfileSentinel):\n    resolve_name = \"scalac-plugins\"\n\n\n@rule\ndef generate_global_scalac_plugins_lockfile_request(\n    _: GlobalScalacPluginsToolLockfileSentinel,\n    loaded_global_plugins: _LoadedGlobalScalacPlugins,\n    scalac_plugins: Scalac,\n) -> JvmToolLockfileRequest:\n    return JvmToolLockfileRequest(\n        artifact_inputs=FrozenOrderedSet(loaded_global_plugins.artifact_address_inputs),\n        resolve_name=\"scalac-plugins\",\n        lockfile_dest=scalac_plugins.plugins_global_lockfile,\n    )\n\n\n@dataclass(frozen=True)\nclass GlobalScalacPlugins:\n    names: tuple[str, ...]\n    classpath: MaterializedClasspath\n\n    def args(self, prefix: str | None = None) -> Iterator[str]:\n        for scalac_plugin_path in self.classpath.classpath_entries(prefix):\n            yield f\"-Xplugin:{scalac_plugin_path}\"\n        for name in self.names:\n            yield f\"-Xplugin-require:{name}\"\n\n\n@rule\nasync def global_scalac_plugins(\n    loaded_global_plugins: _LoadedGlobalScalacPlugins,\n) -> GlobalScalacPlugins:\n\n    lockfile = await Get(CoursierResolvedLockfile, GlobalScalacPluginsToolLockfileSentinel())\n    classpath = await Get(\n        MaterializedClasspath,\n        MaterializedClasspathRequest(\n            prefix=\"__scalac_plugin_cp\",\n            lockfiles=(lockfile,),\n        ),\n    )\n    return GlobalScalacPlugins(loaded_global_plugins.names, classpath)\n\n\ndef rules():\n    return (\n        *collect_rules(),\n        *jvm_tool_rules(),\n        UnionRule(JvmToolLockfileSentinel, GlobalScalacPluginsToolLockfileSentinel),\n    )\n", "path": "src/python/pants/backend/scala/compile/scalac_plugins.py"}]}