We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix Scala using `add_dependencies_on_all_siblings=True`
After dependency inference was improved for Scala, `add_dependencies_on_all_siblings` was not removed:
https://github.com/pantsbuild/pants/blob/c2f6404c1ed5fd11a6a37eac8682a5d337bf22aa/src/python/pants/backend/scala/target_types.py#L233 This means that we are overly coarsening Scala (all BUILD targets end up compiled together).

We should fix this (or drive it via an option), but it will definitely impact compilation success rates, and might also impact performance. We should test out the impact in our testbed repositories.

--- 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/target_types.py`
Content:
```
1 # Copyright 2020 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 
8 from pants.engine.rules import collect_rules, rule
9 from pants.engine.target import (
10     COMMON_TARGET_FIELDS,
11     AsyncFieldMixin,
12     Dependencies,
13     FieldSet,
14     MultipleSourcesField,
15     SingleSourceField,
16     StringField,
17     StringSequenceField,
18     Target,
19     TargetFilesGenerator,
20     TargetFilesGeneratorSettings,
21     TargetFilesGeneratorSettingsRequest,
22     generate_multiple_sources_field_help_message,
23 )
24 from pants.engine.unions import UnionRule
25 from pants.jvm.target_types import (
26     JunitTestSourceField,
27     JvmJdkField,
28     JvmProvidesTypesField,
29     JvmResolveField,
30 )
31 from pants.util.strutil import softwrap
32 
33 
34 class ScalaSettingsRequest(TargetFilesGeneratorSettingsRequest):
35     pass
36 
37 
38 @rule
39 def scala_settings_request(_: ScalaSettingsRequest) -> TargetFilesGeneratorSettings:
40     # TODO: See https://github.com/pantsbuild/pants/issues/14382.
41     return TargetFilesGeneratorSettings(add_dependencies_on_all_siblings=True)
42 
43 
44 class ScalaSourceField(SingleSourceField):
45     expected_file_extensions = (".scala",)
46 
47 
48 class ScalaGeneratorSourcesField(MultipleSourcesField):
49     expected_file_extensions = (".scala",)
50 
51 
52 class ScalaDependenciesField(Dependencies):
53     pass
54 
55 
56 class ScalaConsumedPluginNamesField(StringSequenceField):
57     help = softwrap(
58         """
59         The names of Scala plugins that this source file requires.
60 
61         The plugin must be defined by a corresponding `scalac_plugin` AND `jvm_artifact` target,
62         and must be present in this target's resolve's lockfile.
63 
64         If not specified, this will default to the plugins specified in
65         `[scalac].plugins_for_resolve` for this target's resolve.
66         """
67     )
68 
69     alias = "scalac_plugins"
70     required = False
71 
72 
73 @dataclass(frozen=True)
74 class ScalaFieldSet(FieldSet):
75     required_fields = (ScalaSourceField,)
76 
77     sources: ScalaSourceField
78 
79 
80 @dataclass(frozen=True)
81 class ScalaGeneratorFieldSet(FieldSet):
82     required_fields = (ScalaGeneratorSourcesField,)
83 
84     sources: ScalaGeneratorSourcesField
85 
86 
87 # -----------------------------------------------------------------------------------------------
88 # `scalatest_tests`
89 # -----------------------------------------------------------------------------------------------
90 
91 
92 class ScalatestTestSourceField(ScalaSourceField):
93     pass
94 
95 
96 class ScalatestTestTarget(Target):
97     alias = "scalatest_test"
98     core_fields = (
99         *COMMON_TARGET_FIELDS,
100         ScalaDependenciesField,
101         ScalatestTestSourceField,
102         ScalaConsumedPluginNamesField,
103         JvmResolveField,
104         JvmProvidesTypesField,
105         JvmJdkField,
106     )
107     help = "A single Scala test, run with Scalatest."
108 
109 
110 class ScalatestTestsGeneratorSourcesField(ScalaGeneratorSourcesField):
111     default = ("*Spec.scala", "*Suite.scala")
112     help = generate_multiple_sources_field_help_message(
113         "Example: `sources=['*Spec.scala', '!SuiteIgnore.scala']`"
114     )
115 
116 
117 class ScalatestTestsGeneratorTarget(TargetFilesGenerator):
118     alias = "scalatest_tests"
119     core_fields = (
120         *COMMON_TARGET_FIELDS,
121         ScalatestTestsGeneratorSourcesField,
122     )
123     generated_target_cls = ScalatestTestTarget
124     copied_fields = COMMON_TARGET_FIELDS
125     moved_fields = (
126         ScalaDependenciesField,
127         ScalaConsumedPluginNamesField,
128         JvmJdkField,
129         JvmProvidesTypesField,
130         JvmResolveField,
131     )
132     settings_request_cls = ScalaSettingsRequest
133     help = softwrap(
134         f"""
135         Generate a `scalatest_test` target for each file in the `sources` field (defaults to
136         all files in the directory matching {ScalatestTestsGeneratorSourcesField.default}).
137         """
138     )
139 
140 
141 # -----------------------------------------------------------------------------------------------
142 # `scala_junit_tests`
143 # -----------------------------------------------------------------------------------------------
144 
145 
146 class ScalaJunitTestSourceField(ScalaSourceField, JunitTestSourceField):
147     pass
148 
149 
150 class ScalaJunitTestTarget(Target):
151     alias = "scala_junit_test"
152     core_fields = (
153         *COMMON_TARGET_FIELDS,
154         ScalaDependenciesField,
155         ScalaJunitTestSourceField,
156         ScalaConsumedPluginNamesField,
157         JvmResolveField,
158         JvmProvidesTypesField,
159         JvmJdkField,
160     )
161     help = "A single Scala test, run with JUnit."
162 
163 
164 class ScalaJunitTestsGeneratorSourcesField(ScalaGeneratorSourcesField):
165     default = ("*Test.scala",)
166     help = generate_multiple_sources_field_help_message(
167         "Example: `sources=['*Test.scala', '!TestIgnore.scala']`"
168     )
169 
170 
171 class ScalaJunitTestsGeneratorTarget(TargetFilesGenerator):
172     alias = "scala_junit_tests"
173     core_fields = (
174         *COMMON_TARGET_FIELDS,
175         ScalaJunitTestsGeneratorSourcesField,
176     )
177     generated_target_cls = ScalaJunitTestTarget
178     copied_fields = COMMON_TARGET_FIELDS
179     moved_fields = (
180         ScalaDependenciesField,
181         ScalaConsumedPluginNamesField,
182         JvmJdkField,
183         JvmProvidesTypesField,
184         JvmResolveField,
185     )
186     settings_request_cls = ScalaSettingsRequest
187     help = "Generate a `scala_junit_test` target for each file in the `sources` field."
188 
189 
190 # -----------------------------------------------------------------------------------------------
191 # `scala_source` target
192 # -----------------------------------------------------------------------------------------------
193 
194 
195 class ScalaSourceTarget(Target):
196     alias = "scala_source"
197     core_fields = (
198         *COMMON_TARGET_FIELDS,
199         ScalaDependenciesField,
200         ScalaSourceField,
201         ScalaConsumedPluginNamesField,
202         JvmResolveField,
203         JvmProvidesTypesField,
204         JvmJdkField,
205     )
206     help = "A single Scala source file containing application or library code."
207 
208 
209 # -----------------------------------------------------------------------------------------------
210 # `scala_sources` target generator
211 # -----------------------------------------------------------------------------------------------
212 
213 
214 class ScalaSourcesGeneratorSourcesField(ScalaGeneratorSourcesField):
215     default = (
216         "*.scala",
217         *(f"!{pat}" for pat in (ScalaJunitTestsGeneratorSourcesField.default)),
218         *(f"!{pat}" for pat in (ScalatestTestsGeneratorSourcesField.default)),
219     )
220     help = generate_multiple_sources_field_help_message(
221         "Example: `sources=['Example.scala', 'New*.scala', '!OldIgnore.scala']`"
222     )
223 
224 
225 class ScalaSourcesGeneratorTarget(TargetFilesGenerator):
226     alias = "scala_sources"
227     core_fields = (
228         *COMMON_TARGET_FIELDS,
229         ScalaSourcesGeneratorSourcesField,
230     )
231     generated_target_cls = ScalaSourceTarget
232     copied_fields = COMMON_TARGET_FIELDS
233     moved_fields = (
234         ScalaDependenciesField,
235         ScalaConsumedPluginNamesField,
236         JvmResolveField,
237         JvmJdkField,
238         JvmProvidesTypesField,
239     )
240     settings_request_cls = ScalaSettingsRequest
241     help = "Generate a `scala_source` target for each file in the `sources` field."
242 
243 
244 # -----------------------------------------------------------------------------------------------
245 # `scalac_plugin` target
246 # -----------------------------------------------------------------------------------------------
247 
248 
249 class ScalacPluginArtifactField(StringField, AsyncFieldMixin):
250     alias = "artifact"
251     required = True
252     value: str
253     help = "The address of a `jvm_artifact` that defines a plugin for `scalac`."
254 
255 
256 class ScalacPluginNameField(StringField):
257     alias = "plugin_name"
258     help = softwrap(
259         """
260         The name that `scalac` should use to load the plugin.
261 
262         If not set, the plugin name defaults to the target name.
263         """
264     )
265 
266 
267 class ScalacPluginTarget(Target):
268     alias = "scalac_plugin"
269     core_fields = (
270         *COMMON_TARGET_FIELDS,
271         ScalacPluginArtifactField,
272         ScalacPluginNameField,
273     )
274     help = softwrap(
275         """
276         A plugin for `scalac`.
277 
278         Currently only thirdparty plugins are supported. To enable a plugin, define this
279         target type, and set the `artifact=` field to the address of a `jvm_artifact` that
280         provides the plugin.
281 
282         If the `scalac`-loaded name of the plugin does not match the target's name,
283         additionally set the `plugin_name=` field.
284         """
285     )
286 
287 
288 def rules():
289     return (
290         *collect_rules(),
291         UnionRule(TargetFilesGeneratorSettingsRequest, ScalaSettingsRequest),
292     )
293
```

Path: `src/python/pants/backend/scala/subsystems/scala_infer.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 pants.option.option_types import BoolOption
5 from pants.option.subsystem import Subsystem
6 
7 
8 class ScalaInferSubsystem(Subsystem):
9     options_scope = "scala-infer"
10     help = "Options controlling which dependencies will be inferred for Scala targets."
11 
12     imports = BoolOption(
13         "--imports",
14         default=True,
15         help="Infer a target's dependencies by parsing import statements from sources.",
16     )
17     consumed_types = BoolOption(
18         "--consumed-types",
19         default=True,
20         help="Infer a target's dependencies by parsing consumed types from sources.",
21     )
22
```
--- 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/subsystems/scala_infer.py b/src/python/pants/backend/scala/subsystems/scala_infer.py
--- a/src/python/pants/backend/scala/subsystems/scala_infer.py
+++ b/src/python/pants/backend/scala/subsystems/scala_infer.py
@@ -3,6 +3,7 @@
 
 from pants.option.option_types import BoolOption
 from pants.option.subsystem import Subsystem
+from pants.util.strutil import softwrap
 
 
 class ScalaInferSubsystem(Subsystem):
@@ -19,3 +20,18 @@
         default=True,
         help="Infer a target's dependencies by parsing consumed types from sources.",
     )
+    force_add_siblings_as_dependencies = BoolOption(
+        "--force-add-siblings-as-dependencies",
+        default=True,
+        help=softwrap(
+            """
+            If true, add a dependency on all scala_source targets generated by the same scala_sources target generator.
+            If false, the dependencies will only be added if [scala-infer].imports is also set to false.
+
+            Setting this option to true reduces the precision of dependency information.
+            That means that you may end up compiling more than is necessary for a particular task,
+            and that compilation will be invalidated more frequently than actually necessary.
+            However, setting to true may be helpful if compilation fails due to missing dependencies.
+            """
+        ),
+    )
diff --git a/src/python/pants/backend/scala/target_types.py b/src/python/pants/backend/scala/target_types.py
--- a/src/python/pants/backend/scala/target_types.py
+++ b/src/python/pants/backend/scala/target_types.py
@@ -5,6 +5,8 @@
 
 from dataclasses import dataclass
 
+from pants.backend.scala.subsystems.scala_infer import ScalaInferSubsystem
+from pants.base.deprecated import warn_or_error
 from pants.engine.rules import collect_rules, rule
 from pants.engine.target import (
     COMMON_TARGET_FIELDS,
@@ -36,9 +38,35 @@
 
 
 @rule
-def scala_settings_request(_: ScalaSettingsRequest) -> TargetFilesGeneratorSettings:
-    # TODO: See https://github.com/pantsbuild/pants/issues/14382.
-    return TargetFilesGeneratorSettings(add_dependencies_on_all_siblings=True)
+def scala_settings_request(
+    scala_infer_subsystem: ScalaInferSubsystem, _: ScalaSettingsRequest
+) -> TargetFilesGeneratorSettings:
+    if scala_infer_subsystem.options.is_default("force_add_siblings_as_dependencies"):
+        warn_or_error(
+            removal_version="2.14.0.dev0",
+            entity="`force_add_siblings_as_dependencies` defaulting to True",
+            hint=softwrap(
+                """
+                Setting this option to true reduces the precision of dependency information.
+                That means that you may end up compiling more than is necessary for a particular task,
+                and that compilation will be invalidated more frequently than actually necessary.
+                However, setting to true may be helpful if compilation fails due to missing dependencies.
+
+                We have made several improvements to Pants's Scala dependency inference,
+                where we no longer think it's necessary to adding dependencies on sibling targets.
+                If you have compilation failures after disabling this option, please consider opening an issue at
+                https://github.com/pantsbuild/pants/issues/new so that we can continue to improve Pants's dependency inference.
+
+                To opt into the new default early, set `force_add_siblings_as_dependencies = false` in the `[scala_infer]`
+                section in `pants.toml`. Otherwise, set to `true` to silence this warning.
+                """
+            ),
+        )
+
+    return TargetFilesGeneratorSettings(
+        add_dependencies_on_all_siblings=scala_infer_subsystem.force_add_siblings_as_dependencies
+        or not scala_infer_subsystem.imports
+    )
 
 
 class ScalaSourceField(SingleSourceField):

{"golden_diff": "diff --git a/src/python/pants/backend/scala/subsystems/scala_infer.py b/src/python/pants/backend/scala/subsystems/scala_infer.py\n--- a/src/python/pants/backend/scala/subsystems/scala_infer.py\n+++ b/src/python/pants/backend/scala/subsystems/scala_infer.py\n@@ -3,6 +3,7 @@\n \n from pants.option.option_types import BoolOption\n from pants.option.subsystem import Subsystem\n+from pants.util.strutil import softwrap\n \n \n class ScalaInferSubsystem(Subsystem):\n@@ -19,3 +20,18 @@\n         default=True,\n         help=\"Infer a target's dependencies by parsing consumed types from sources.\",\n     )\n+    force_add_siblings_as_dependencies = BoolOption(\n+        \"--force-add-siblings-as-dependencies\",\n+        default=True,\n+        help=softwrap(\n+            \"\"\"\n+            If true, add a dependency on all scala_source targets generated by the same scala_sources target generator.\n+            If false, the dependencies will only be added if [scala-infer].imports is also set to false.\n+\n+            Setting this option to true reduces the precision of dependency information.\n+            That means that you may end up compiling more than is necessary for a particular task,\n+            and that compilation will be invalidated more frequently than actually necessary.\n+            However, setting to true may be helpful if compilation fails due to missing dependencies.\n+            \"\"\"\n+        ),\n+    )\ndiff --git a/src/python/pants/backend/scala/target_types.py b/src/python/pants/backend/scala/target_types.py\n--- a/src/python/pants/backend/scala/target_types.py\n+++ b/src/python/pants/backend/scala/target_types.py\n@@ -5,6 +5,8 @@\n \n from dataclasses import dataclass\n \n+from pants.backend.scala.subsystems.scala_infer import ScalaInferSubsystem\n+from pants.base.deprecated import warn_or_error\n from pants.engine.rules import collect_rules, rule\n from pants.engine.target import (\n     COMMON_TARGET_FIELDS,\n@@ -36,9 +38,35 @@\n \n \n @rule\n-def scala_settings_request(_: ScalaSettingsRequest) -> TargetFilesGeneratorSettings:\n-    # TODO: See https://github.com/pantsbuild/pants/issues/14382.\n-    return TargetFilesGeneratorSettings(add_dependencies_on_all_siblings=True)\n+def scala_settings_request(\n+    scala_infer_subsystem: ScalaInferSubsystem, _: ScalaSettingsRequest\n+) -> TargetFilesGeneratorSettings:\n+    if scala_infer_subsystem.options.is_default(\"force_add_siblings_as_dependencies\"):\n+        warn_or_error(\n+            removal_version=\"2.14.0.dev0\",\n+            entity=\"`force_add_siblings_as_dependencies` defaulting to True\",\n+            hint=softwrap(\n+                \"\"\"\n+                Setting this option to true reduces the precision of dependency information.\n+                That means that you may end up compiling more than is necessary for a particular task,\n+                and that compilation will be invalidated more frequently than actually necessary.\n+                However, setting to true may be helpful if compilation fails due to missing dependencies.\n+\n+                We have made several improvements to Pants's Scala dependency inference,\n+                where we no longer think it's necessary to adding dependencies on sibling targets.\n+                If you have compilation failures after disabling this option, please consider opening an issue at\n+                https://github.com/pantsbuild/pants/issues/new so that we can continue to improve Pants's dependency inference.\n+\n+                To opt into the new default early, set `force_add_siblings_as_dependencies = false` in the `[scala_infer]`\n+                section in `pants.toml`. Otherwise, set to `true` to silence this warning.\n+                \"\"\"\n+            ),\n+        )\n+\n+    return TargetFilesGeneratorSettings(\n+        add_dependencies_on_all_siblings=scala_infer_subsystem.force_add_siblings_as_dependencies\n+        or not scala_infer_subsystem.imports\n+    )\n \n \n class ScalaSourceField(SingleSourceField):\n", "issue": "Fix Scala using `add_dependencies_on_all_siblings=True`\nAfter dependency inference was improved for Scala, `add_dependencies_on_all_siblings` was not removed:\r\nhttps://github.com/pantsbuild/pants/blob/c2f6404c1ed5fd11a6a37eac8682a5d337bf22aa/src/python/pants/backend/scala/target_types.py#L233 This means that we are overly coarsening Scala (all BUILD targets end up compiled together).\r\n\r\nWe should fix this (or drive it via an option), but it will definitely impact compilation success rates, and might also impact performance. We should test out the impact in our testbed repositories.\n", "before_files": [{"content": "# Copyright 2020 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\n\nfrom pants.engine.rules import collect_rules, rule\nfrom pants.engine.target import (\n    COMMON_TARGET_FIELDS,\n    AsyncFieldMixin,\n    Dependencies,\n    FieldSet,\n    MultipleSourcesField,\n    SingleSourceField,\n    StringField,\n    StringSequenceField,\n    Target,\n    TargetFilesGenerator,\n    TargetFilesGeneratorSettings,\n    TargetFilesGeneratorSettingsRequest,\n    generate_multiple_sources_field_help_message,\n)\nfrom pants.engine.unions import UnionRule\nfrom pants.jvm.target_types import (\n    JunitTestSourceField,\n    JvmJdkField,\n    JvmProvidesTypesField,\n    JvmResolveField,\n)\nfrom pants.util.strutil import softwrap\n\n\nclass ScalaSettingsRequest(TargetFilesGeneratorSettingsRequest):\n    pass\n\n\n@rule\ndef scala_settings_request(_: ScalaSettingsRequest) -> TargetFilesGeneratorSettings:\n    # TODO: See https://github.com/pantsbuild/pants/issues/14382.\n    return TargetFilesGeneratorSettings(add_dependencies_on_all_siblings=True)\n\n\nclass ScalaSourceField(SingleSourceField):\n    expected_file_extensions = (\".scala\",)\n\n\nclass ScalaGeneratorSourcesField(MultipleSourcesField):\n    expected_file_extensions = (\".scala\",)\n\n\nclass ScalaDependenciesField(Dependencies):\n    pass\n\n\nclass ScalaConsumedPluginNamesField(StringSequenceField):\n    help = softwrap(\n        \"\"\"\n        The names of Scala plugins that this source file requires.\n\n        The plugin must be defined by a corresponding `scalac_plugin` AND `jvm_artifact` target,\n        and must be present in this target's resolve's lockfile.\n\n        If not specified, this will default to the plugins specified in\n        `[scalac].plugins_for_resolve` for this target's resolve.\n        \"\"\"\n    )\n\n    alias = \"scalac_plugins\"\n    required = False\n\n\n@dataclass(frozen=True)\nclass ScalaFieldSet(FieldSet):\n    required_fields = (ScalaSourceField,)\n\n    sources: ScalaSourceField\n\n\n@dataclass(frozen=True)\nclass ScalaGeneratorFieldSet(FieldSet):\n    required_fields = (ScalaGeneratorSourcesField,)\n\n    sources: ScalaGeneratorSourcesField\n\n\n# -----------------------------------------------------------------------------------------------\n# `scalatest_tests`\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalatestTestSourceField(ScalaSourceField):\n    pass\n\n\nclass ScalatestTestTarget(Target):\n    alias = \"scalatest_test\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalatestTestSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala test, run with Scalatest.\"\n\n\nclass ScalatestTestsGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\"*Spec.scala\", \"*Suite.scala\")\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['*Spec.scala', '!SuiteIgnore.scala']`\"\n    )\n\n\nclass ScalatestTestsGeneratorTarget(TargetFilesGenerator):\n    alias = \"scalatest_tests\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalatestTestsGeneratorSourcesField,\n    )\n    generated_target_cls = ScalatestTestTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n        JvmResolveField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = softwrap(\n        f\"\"\"\n        Generate a `scalatest_test` target for each file in the `sources` field (defaults to\n        all files in the directory matching {ScalatestTestsGeneratorSourcesField.default}).\n        \"\"\"\n    )\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_junit_tests`\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaJunitTestSourceField(ScalaSourceField, JunitTestSourceField):\n    pass\n\n\nclass ScalaJunitTestTarget(Target):\n    alias = \"scala_junit_test\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalaJunitTestSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala test, run with JUnit.\"\n\n\nclass ScalaJunitTestsGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\"*Test.scala\",)\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['*Test.scala', '!TestIgnore.scala']`\"\n    )\n\n\nclass ScalaJunitTestsGeneratorTarget(TargetFilesGenerator):\n    alias = \"scala_junit_tests\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaJunitTestsGeneratorSourcesField,\n    )\n    generated_target_cls = ScalaJunitTestTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n        JvmResolveField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = \"Generate a `scala_junit_test` target for each file in the `sources` field.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_source` target\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaSourceTarget(Target):\n    alias = \"scala_source\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalaSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala source file containing application or library code.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_sources` target generator\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaSourcesGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\n        \"*.scala\",\n        *(f\"!{pat}\" for pat in (ScalaJunitTestsGeneratorSourcesField.default)),\n        *(f\"!{pat}\" for pat in (ScalatestTestsGeneratorSourcesField.default)),\n    )\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['Example.scala', 'New*.scala', '!OldIgnore.scala']`\"\n    )\n\n\nclass ScalaSourcesGeneratorTarget(TargetFilesGenerator):\n    alias = \"scala_sources\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaSourcesGeneratorSourcesField,\n    )\n    generated_target_cls = ScalaSourceTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = \"Generate a `scala_source` target for each file in the `sources` field.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scalac_plugin` target\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalacPluginArtifactField(StringField, AsyncFieldMixin):\n    alias = \"artifact\"\n    required = True\n    value: str\n    help = \"The address of a `jvm_artifact` that defines a plugin for `scalac`.\"\n\n\nclass ScalacPluginNameField(StringField):\n    alias = \"plugin_name\"\n    help = softwrap(\n        \"\"\"\n        The name that `scalac` should use to load the plugin.\n\n        If not set, the plugin name defaults to the target name.\n        \"\"\"\n    )\n\n\nclass ScalacPluginTarget(Target):\n    alias = \"scalac_plugin\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalacPluginArtifactField,\n        ScalacPluginNameField,\n    )\n    help = softwrap(\n        \"\"\"\n        A plugin for `scalac`.\n\n        Currently only thirdparty plugins are supported. To enable a plugin, define this\n        target type, and set the `artifact=` field to the address of a `jvm_artifact` that\n        provides the plugin.\n\n        If the `scalac`-loaded name of the plugin does not match the target's name,\n        additionally set the `plugin_name=` field.\n        \"\"\"\n    )\n\n\ndef rules():\n    return (\n        *collect_rules(),\n        UnionRule(TargetFilesGeneratorSettingsRequest, ScalaSettingsRequest),\n    )\n", "path": "src/python/pants/backend/scala/target_types.py"}, {"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom pants.option.option_types import BoolOption\nfrom pants.option.subsystem import Subsystem\n\n\nclass ScalaInferSubsystem(Subsystem):\n    options_scope = \"scala-infer\"\n    help = \"Options controlling which dependencies will be inferred for Scala targets.\"\n\n    imports = BoolOption(\n        \"--imports\",\n        default=True,\n        help=\"Infer a target's dependencies by parsing import statements from sources.\",\n    )\n    consumed_types = BoolOption(\n        \"--consumed-types\",\n        default=True,\n        help=\"Infer a target's dependencies by parsing consumed types from sources.\",\n    )\n", "path": "src/python/pants/backend/scala/subsystems/scala_infer.py"}], "after_files": [{"content": "# Copyright 2020 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\n\nfrom pants.backend.scala.subsystems.scala_infer import ScalaInferSubsystem\nfrom pants.base.deprecated import warn_or_error\nfrom pants.engine.rules import collect_rules, rule\nfrom pants.engine.target import (\n    COMMON_TARGET_FIELDS,\n    AsyncFieldMixin,\n    Dependencies,\n    FieldSet,\n    MultipleSourcesField,\n    SingleSourceField,\n    StringField,\n    StringSequenceField,\n    Target,\n    TargetFilesGenerator,\n    TargetFilesGeneratorSettings,\n    TargetFilesGeneratorSettingsRequest,\n    generate_multiple_sources_field_help_message,\n)\nfrom pants.engine.unions import UnionRule\nfrom pants.jvm.target_types import (\n    JunitTestSourceField,\n    JvmJdkField,\n    JvmProvidesTypesField,\n    JvmResolveField,\n)\nfrom pants.util.strutil import softwrap\n\n\nclass ScalaSettingsRequest(TargetFilesGeneratorSettingsRequest):\n    pass\n\n\n@rule\ndef scala_settings_request(\n    scala_infer_subsystem: ScalaInferSubsystem, _: ScalaSettingsRequest\n) -> TargetFilesGeneratorSettings:\n    if scala_infer_subsystem.options.is_default(\"force_add_siblings_as_dependencies\"):\n        warn_or_error(\n            removal_version=\"2.14.0.dev0\",\n            entity=\"`force_add_siblings_as_dependencies` defaulting to True\",\n            hint=softwrap(\n                \"\"\"\n                Setting this option to true reduces the precision of dependency information.\n                That means that you may end up compiling more than is necessary for a particular task,\n                and that compilation will be invalidated more frequently than actually necessary.\n                However, setting to true may be helpful if compilation fails due to missing dependencies.\n\n                We have made several improvements to Pants's Scala dependency inference,\n                where we no longer think it's necessary to adding dependencies on sibling targets.\n                If you have compilation failures after disabling this option, please consider opening an issue at\n                https://github.com/pantsbuild/pants/issues/new so that we can continue to improve Pants's dependency inference.\n\n                To opt into the new default early, set `force_add_siblings_as_dependencies = false` in the `[scala_infer]`\n                section in `pants.toml`. Otherwise, set to `true` to silence this warning.\n                \"\"\"\n            ),\n        )\n\n    return TargetFilesGeneratorSettings(\n        add_dependencies_on_all_siblings=scala_infer_subsystem.force_add_siblings_as_dependencies\n        or not scala_infer_subsystem.imports\n    )\n\n\nclass ScalaSourceField(SingleSourceField):\n    expected_file_extensions = (\".scala\",)\n\n\nclass ScalaGeneratorSourcesField(MultipleSourcesField):\n    expected_file_extensions = (\".scala\",)\n\n\nclass ScalaDependenciesField(Dependencies):\n    pass\n\n\nclass ScalaConsumedPluginNamesField(StringSequenceField):\n    help = softwrap(\n        \"\"\"\n        The names of Scala plugins that this source file requires.\n\n        The plugin must be defined by a corresponding `scalac_plugin` AND `jvm_artifact` target,\n        and must be present in this target's resolve's lockfile.\n\n        If not specified, this will default to the plugins specified in\n        `[scalac].plugins_for_resolve` for this target's resolve.\n        \"\"\"\n    )\n\n    alias = \"scalac_plugins\"\n    required = False\n\n\n@dataclass(frozen=True)\nclass ScalaFieldSet(FieldSet):\n    required_fields = (ScalaSourceField,)\n\n    sources: ScalaSourceField\n\n\n@dataclass(frozen=True)\nclass ScalaGeneratorFieldSet(FieldSet):\n    required_fields = (ScalaGeneratorSourcesField,)\n\n    sources: ScalaGeneratorSourcesField\n\n\n# -----------------------------------------------------------------------------------------------\n# `scalatest_tests`\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalatestTestSourceField(ScalaSourceField):\n    pass\n\n\nclass ScalatestTestTarget(Target):\n    alias = \"scalatest_test\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalatestTestSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala test, run with Scalatest.\"\n\n\nclass ScalatestTestsGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\"*Spec.scala\", \"*Suite.scala\")\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['*Spec.scala', '!SuiteIgnore.scala']`\"\n    )\n\n\nclass ScalatestTestsGeneratorTarget(TargetFilesGenerator):\n    alias = \"scalatest_tests\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalatestTestsGeneratorSourcesField,\n    )\n    generated_target_cls = ScalatestTestTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n        JvmResolveField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = softwrap(\n        f\"\"\"\n        Generate a `scalatest_test` target for each file in the `sources` field (defaults to\n        all files in the directory matching {ScalatestTestsGeneratorSourcesField.default}).\n        \"\"\"\n    )\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_junit_tests`\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaJunitTestSourceField(ScalaSourceField, JunitTestSourceField):\n    pass\n\n\nclass ScalaJunitTestTarget(Target):\n    alias = \"scala_junit_test\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalaJunitTestSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala test, run with JUnit.\"\n\n\nclass ScalaJunitTestsGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\"*Test.scala\",)\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['*Test.scala', '!TestIgnore.scala']`\"\n    )\n\n\nclass ScalaJunitTestsGeneratorTarget(TargetFilesGenerator):\n    alias = \"scala_junit_tests\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaJunitTestsGeneratorSourcesField,\n    )\n    generated_target_cls = ScalaJunitTestTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n        JvmResolveField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = \"Generate a `scala_junit_test` target for each file in the `sources` field.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_source` target\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaSourceTarget(Target):\n    alias = \"scala_source\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaDependenciesField,\n        ScalaSourceField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmProvidesTypesField,\n        JvmJdkField,\n    )\n    help = \"A single Scala source file containing application or library code.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scala_sources` target generator\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalaSourcesGeneratorSourcesField(ScalaGeneratorSourcesField):\n    default = (\n        \"*.scala\",\n        *(f\"!{pat}\" for pat in (ScalaJunitTestsGeneratorSourcesField.default)),\n        *(f\"!{pat}\" for pat in (ScalatestTestsGeneratorSourcesField.default)),\n    )\n    help = generate_multiple_sources_field_help_message(\n        \"Example: `sources=['Example.scala', 'New*.scala', '!OldIgnore.scala']`\"\n    )\n\n\nclass ScalaSourcesGeneratorTarget(TargetFilesGenerator):\n    alias = \"scala_sources\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalaSourcesGeneratorSourcesField,\n    )\n    generated_target_cls = ScalaSourceTarget\n    copied_fields = COMMON_TARGET_FIELDS\n    moved_fields = (\n        ScalaDependenciesField,\n        ScalaConsumedPluginNamesField,\n        JvmResolveField,\n        JvmJdkField,\n        JvmProvidesTypesField,\n    )\n    settings_request_cls = ScalaSettingsRequest\n    help = \"Generate a `scala_source` target for each file in the `sources` field.\"\n\n\n# -----------------------------------------------------------------------------------------------\n# `scalac_plugin` target\n# -----------------------------------------------------------------------------------------------\n\n\nclass ScalacPluginArtifactField(StringField, AsyncFieldMixin):\n    alias = \"artifact\"\n    required = True\n    value: str\n    help = \"The address of a `jvm_artifact` that defines a plugin for `scalac`.\"\n\n\nclass ScalacPluginNameField(StringField):\n    alias = \"plugin_name\"\n    help = softwrap(\n        \"\"\"\n        The name that `scalac` should use to load the plugin.\n\n        If not set, the plugin name defaults to the target name.\n        \"\"\"\n    )\n\n\nclass ScalacPluginTarget(Target):\n    alias = \"scalac_plugin\"\n    core_fields = (\n        *COMMON_TARGET_FIELDS,\n        ScalacPluginArtifactField,\n        ScalacPluginNameField,\n    )\n    help = softwrap(\n        \"\"\"\n        A plugin for `scalac`.\n\n        Currently only thirdparty plugins are supported. To enable a plugin, define this\n        target type, and set the `artifact=` field to the address of a `jvm_artifact` that\n        provides the plugin.\n\n        If the `scalac`-loaded name of the plugin does not match the target's name,\n        additionally set the `plugin_name=` field.\n        \"\"\"\n    )\n\n\ndef rules():\n    return (\n        *collect_rules(),\n        UnionRule(TargetFilesGeneratorSettingsRequest, ScalaSettingsRequest),\n    )\n", "path": "src/python/pants/backend/scala/target_types.py"}, {"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom pants.option.option_types import BoolOption\nfrom pants.option.subsystem import Subsystem\nfrom pants.util.strutil import softwrap\n\n\nclass ScalaInferSubsystem(Subsystem):\n    options_scope = \"scala-infer\"\n    help = \"Options controlling which dependencies will be inferred for Scala targets.\"\n\n    imports = BoolOption(\n        \"--imports\",\n        default=True,\n        help=\"Infer a target's dependencies by parsing import statements from sources.\",\n    )\n    consumed_types = BoolOption(\n        \"--consumed-types\",\n        default=True,\n        help=\"Infer a target's dependencies by parsing consumed types from sources.\",\n    )\n    force_add_siblings_as_dependencies = BoolOption(\n        \"--force-add-siblings-as-dependencies\",\n        default=True,\n        help=softwrap(\n            \"\"\"\n            If true, add a dependency on all scala_source targets generated by the same scala_sources target generator.\n            If false, the dependencies will only be added if [scala-infer].imports is also set to false.\n\n            Setting this option to true reduces the precision of dependency information.\n            That means that you may end up compiling more than is necessary for a particular task,\n            and that compilation will be invalidated more frequently than actually necessary.\n            However, setting to true may be helpful if compilation fails due to missing dependencies.\n            \"\"\"\n        ),\n    )\n", "path": "src/python/pants/backend/scala/subsystems/scala_infer.py"}]}