• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 23177125175

17 Mar 2026 03:32AM UTC coverage: 52.677% (-40.3%) from 92.932%
23177125175

Pull #23177

github

web-flow
Merge 1824dfbf4 into 0b9fdfb0e
Pull Request #23177: Bump the gha-deps group across 1 directory with 4 updates

31687 of 60153 relevant lines covered (52.68%)

1.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.68
/src/python/pants/backend/kotlin/target_types.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
from dataclasses import dataclass
2✔
7

8
from pants.engine.internals.native_engine import AddressInput
2✔
9
from pants.engine.target import (
2✔
10
    COMMON_TARGET_FIELDS,
11
    AsyncFieldMixin,
12
    Dependencies,
13
    FieldSet,
14
    MultipleSourcesField,
15
    SingleSourceField,
16
    StringField,
17
    StringSequenceField,
18
    Target,
19
    TargetFilesGenerator,
20
    generate_multiple_sources_field_help_message,
21
)
22
from pants.jvm.run import jvm_run_rules
2✔
23
from pants.jvm.target_types import (
2✔
24
    JunitTestExtraEnvVarsField,
25
    JunitTestSourceField,
26
    JunitTestTimeoutField,
27
    JvmJdkField,
28
    JvmMainClassNameField,
29
    JvmProvidesTypesField,
30
    JvmResolveField,
31
    JvmRunnableSourceFieldSet,
32
)
33
from pants.util.strutil import help_text
2✔
34

35

36
class KotlinSourceField(SingleSourceField):
2✔
37
    expected_file_extensions = (".kt",)
2✔
38

39

40
class KotlinGeneratorSourcesField(MultipleSourcesField):
2✔
41
    expected_file_extensions = (".kt",)
2✔
42

43

44
class KotlincConsumedPluginIdsField(StringSequenceField):
2✔
45
    help = help_text(
2✔
46
        """
47
        The IDs of Kotlin compiler plugins that this source file requires.
48

49
        The plugin must be defined by a corresponding `kotlinc_plugin` AND `jvm_artifact` target,
50
        and must be present in this target's resolve's lockfile.
51

52
        If not specified, this will default to the plugins specified in
53
        `[kotlinc].plugins_for_resolve` for this target's resolve.
54
        """
55
    )
56

57
    alias = "kotlinc_plugins"
2✔
58
    required = False
2✔
59

60

61
@dataclass(frozen=True)
2✔
62
class KotlinFieldSet(JvmRunnableSourceFieldSet):
2✔
63
    required_fields = (KotlinSourceField,)
2✔
64

65
    sources: KotlinSourceField
2✔
66

67

68
@dataclass(frozen=True)
2✔
69
class KotlinGeneratorFieldSet(FieldSet):
2✔
70
    required_fields = (KotlinGeneratorSourcesField,)
2✔
71

72
    sources: KotlinGeneratorSourcesField
2✔
73

74

75
class KotlinDependenciesField(Dependencies):
2✔
76
    pass
2✔
77

78

79
# -----------------------------------------------------------------------------------------------
80
# `kotlin_source` and `kotlin_sources` targets
81
# -----------------------------------------------------------------------------------------------
82

83

84
class KotlinSourceTarget(Target):
2✔
85
    alias = "kotlin_source"
2✔
86
    core_fields = (
2✔
87
        *COMMON_TARGET_FIELDS,
88
        KotlinDependenciesField,
89
        KotlinSourceField,
90
        KotlincConsumedPluginIdsField,
91
        JvmResolveField,
92
        JvmProvidesTypesField,
93
        JvmJdkField,
94
        JvmMainClassNameField,
95
    )
96
    help = "A single Kotlin source file containing application or library code."
2✔
97

98

99
class KotlinSourcesGeneratorSourcesField(KotlinGeneratorSourcesField):
2✔
100
    default = ("*.kt",)
2✔
101
    help = generate_multiple_sources_field_help_message(
2✔
102
        "Example: `sources=['Example.kt', 'New*.kt', '!OldIgnore.kt']`"
103
    )
104

105

106
class KotlinSourcesGeneratorTarget(TargetFilesGenerator):
2✔
107
    alias = "kotlin_sources"
2✔
108
    core_fields = (
2✔
109
        *COMMON_TARGET_FIELDS,
110
        KotlinSourcesGeneratorSourcesField,
111
    )
112
    generated_target_cls = KotlinSourceTarget
2✔
113
    copied_fields = COMMON_TARGET_FIELDS
2✔
114
    moved_fields = (
2✔
115
        KotlinDependenciesField,
116
        KotlincConsumedPluginIdsField,
117
        JvmResolveField,
118
        JvmJdkField,
119
        JvmProvidesTypesField,
120
        JvmMainClassNameField,
121
    )
122
    help = "Generate a `kotlin_source` target for each file in the `sources` field."
2✔
123

124

125
# -----------------------------------------------------------------------------------------------
126
# `kotlin_junit_tests`
127
# -----------------------------------------------------------------------------------------------
128

129

130
class KotlinJunitTestSourceField(KotlinSourceField, JunitTestSourceField):
2✔
131
    pass
2✔
132

133

134
class KotlinJunitTestDependenciesField(KotlinDependenciesField):
2✔
135
    pass
2✔
136

137

138
class KotlinJunitTestTarget(Target):
2✔
139
    alias = "kotlin_junit_test"
2✔
140
    core_fields = (
2✔
141
        *COMMON_TARGET_FIELDS,
142
        KotlinJunitTestDependenciesField,
143
        KotlinJunitTestSourceField,
144
        KotlincConsumedPluginIdsField,
145
        JunitTestTimeoutField,
146
        JunitTestExtraEnvVarsField,
147
        JvmResolveField,
148
        JvmJdkField,
149
        JvmProvidesTypesField,
150
    )
151
    help = "A single Kotlin test, run with JUnit."
2✔
152

153

154
class KotlinJunitTestsGeneratorSourcesField(KotlinGeneratorSourcesField):
2✔
155
    default = ("*Test.kt",)
2✔
156
    help = generate_multiple_sources_field_help_message(
2✔
157
        "Example: `sources=['*Test.kt', '!TestIgnore.kt']`"
158
    )
159

160

161
class KotlinJunitTestsGeneratorTarget(TargetFilesGenerator):
2✔
162
    alias = "kotlin_junit_tests"
2✔
163
    core_fields = (
2✔
164
        *COMMON_TARGET_FIELDS,
165
        KotlinJunitTestsGeneratorSourcesField,
166
    )
167
    generated_target_cls = KotlinJunitTestTarget
2✔
168
    copied_fields = COMMON_TARGET_FIELDS
2✔
169
    moved_fields = (
2✔
170
        KotlinJunitTestDependenciesField,
171
        KotlincConsumedPluginIdsField,
172
        JunitTestTimeoutField,
173
        JunitTestExtraEnvVarsField,
174
        JvmResolveField,
175
        JvmJdkField,
176
        JvmProvidesTypesField,
177
    )
178
    help = "Generate a `kotlin_junit_test` target for each file in the `sources` field."
2✔
179

180

181
# -----------------------------------------------------------------------------------------------
182
# `kotlinc_plugin` target type
183
# -----------------------------------------------------------------------------------------------
184

185

186
class KotlincPluginArtifactField(StringField, AsyncFieldMixin):
2✔
187
    alias = "artifact"
2✔
188
    required = True
2✔
189
    value: str
2✔
190
    help = "The address of a `jvm_artifact` that defines a plugin for `kotlinc`."
2✔
191

192
    def to_address_input(self) -> AddressInput:
2✔
193
        return AddressInput.parse(
×
194
            self.value,
195
            relative_to=self.address.spec_path,
196
            description_of_origin=(
197
                f"the `{self.alias}` field in the `{KotlincPluginTarget.alias}` target {self.address}"
198
            ),
199
        )
200

201

202
class KotlincPluginIdField(StringField):
2✔
203
    alias = "plugin_id"
2✔
204
    help = help_text(
2✔
205
        """
206
        The ID for `kotlinc` to use when setting options for the plugin.
207

208
        If not set, the plugin ID defaults to the target name.
209
        """
210
    )
211

212

213
class KotlincPluginArgsField(StringSequenceField):
2✔
214
    alias = "plugin_args"
2✔
215
    help = help_text(
2✔
216
        """
217
        Optional list of argument to pass to the plugin.
218
        """
219
    )
220

221

222
class KotlincPluginTarget(Target):
2✔
223
    alias = "kotlinc_plugin"
2✔
224
    core_fields = (
2✔
225
        *COMMON_TARGET_FIELDS,
226
        KotlincPluginArtifactField,
227
        KotlincPluginIdField,
228
        KotlincPluginArgsField,
229
    )
230
    help = help_text(
2✔
231
        """
232
        A plugin for `kotlinc`.
233

234
        To enable a `kotlinc` plugin, define a target with this target type, and set the `artifact` field to the
235
        address of a `jvm_artifact` target that provides the plugin. Set the `plugin_id` field to the ID of the
236
        plugin if that name cannot be inferred from the `name` of this target.
237

238
        The standard `kotlinc` plugins are available via the following artifact coordinates and IDs:
239

240
        * All-open: `org.jetbrains.kotlin:kotlin-allopen:VERSION` (ID: `all-open`)
241
        * No-arg: `org.jetbrains.kotlin:kotlin-noarg:VERSION` (ID: `no-arg`)
242
        * SAM with receiver: `org.jetbrains.kotlin:kotlin-sam-with-receiver:VERSION` (ID: `sam-with-receiver`)
243
        * kapt (annotation processor): `org.jetbrains.kotlin:org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:VERSION` (ID: `kapt3`)
244
        * Serialization: `org.jetbrains.kotlin:kotlin-serialization:VERSION` (ID: `serialization`)
245
        """
246
    )
247

248

249
def rules():
2✔
250
    return [
2✔
251
        *jvm_run_rules(KotlinFieldSet),
252
    ]
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc