forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
workspace_defs.bzl
292 lines (253 loc) · 10.6 KB
/
workspace_defs.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# Copyright (C) 2020 The Google Bazel Common Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A macro to configure Dagger deps within a workspace"""
load("//:build_defs.bzl", "POM_VERSION")
_DAGGER_VERSION = POM_VERSION
_HILT_VERSION = POM_VERSION
DAGGER_ARTIFACTS = [
"com.google.dagger:dagger:" + _DAGGER_VERSION,
"com.google.dagger:dagger-compiler:" + _DAGGER_VERSION,
"com.google.dagger:dagger-producers:" + _DAGGER_VERSION,
"com.google.dagger:dagger-spi:" + _DAGGER_VERSION,
]
DAGGER_ANDROID_ARTIFACTS = [
"com.google.dagger:dagger-android-processor:" + _DAGGER_VERSION,
"com.google.dagger:dagger-android-support:" + _DAGGER_VERSION,
"com.google.dagger:dagger-android:" + _DAGGER_VERSION,
]
HILT_ANDROID_ARTIFACTS = [
"androidx.test:core:1.1.0", # Export for ApplicationProvider
"javax.annotation:jsr250-api:1.0", # Export for @Generated
"androidx.annotation:annotation:1.1.0", # Export for @CallSuper/@Nullable
"com.google.dagger:dagger:" + _DAGGER_VERSION,
"com.google.dagger:dagger-compiler:" + _DAGGER_VERSION,
"com.google.dagger:hilt-android:" + _HILT_VERSION,
"com.google.dagger:hilt-android-testing:" + _HILT_VERSION,
"com.google.dagger:hilt-android-compiler:" + _HILT_VERSION,
]
DAGGER_REPOSITORIES = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
]
DAGGER_ANDROID_REPOSITORIES = DAGGER_REPOSITORIES
HILT_ANDROID_REPOSITORIES = DAGGER_REPOSITORIES
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#unnamed-macro
# buildifier: disable=unnamed-macro
def dagger_rules(repo_name = "@maven"):
"""Defines the Dagger targets with proper exported dependencies and plugins.
The targets will be of the form ":<artifact-id>".
Args:
repo_name: The name of the dependency repository (default is "@maven").
"""
native.java_library(
name = "dagger",
exported_plugins = [":dagger-compiler"],
visibility = ["//visibility:public"],
exports = [
"%s//:com_google_dagger_dagger" % repo_name,
"%s//:javax_inject_javax_inject" % repo_name,
],
)
native.java_plugin(
name = "dagger-compiler",
generates_api = 1,
processor_class = "dagger.internal.codegen.ComponentProcessor",
deps = [
"%s//:com_google_dagger_dagger_compiler" % repo_name,
],
)
native.java_library(
name = "dagger-producers",
visibility = ["//visibility:public"],
exports = [
":dagger",
"%s//:com_google_dagger_dagger_producers" % repo_name,
],
)
native.java_library(
name = "dagger-spi",
visibility = ["//visibility:public"],
exports = [
"%s//:com_google_dagger_dagger_spi" % repo_name,
],
)
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#unnamed-macro
# buildifier: disable=unnamed-macro
def dagger_android_rules(repo_name = "@maven"):
"""Defines the Dagger Android targets with proper exported dependencies and plugins.
The targets will be of the form ":<artifact-id>".
Args:
repo_name: The name of the dependency repository (default is "@maven").
"""
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-android
# buildifier: disable=native-android
native.android_library(
name = "dagger-android",
exported_plugins = [":dagger-android-processor"],
visibility = ["//visibility:public"],
exports = [
"%s//:com_google_dagger_dagger_android" % repo_name,
],
)
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-android
# buildifier: disable=native-android
native.android_library(
name = "dagger-android-support",
exported_plugins = [":dagger-android-processor"],
visibility = ["//visibility:public"],
exports = [
":dagger-android",
"%s//:com_google_dagger_dagger_android_support" % repo_name,
],
)
native.java_plugin(
name = "dagger-android-processor",
generates_api = 1,
processor_class = "dagger.android.processor.AndroidProcessor",
deps = [
"%s//:com_google_dagger_dagger_android_processor" % repo_name,
],
)
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#unnamed-macro
# buildifier: disable=unnamed-macro
def hilt_android_rules(repo_name = "@maven"):
"""Defines the Hilt Android targets with proper exported dependencies and plugins.
The targets will be of the form ":<artifact-id>".
Args:
repo_name: The name of the dependency repository (default is "@maven").
"""
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-android
# buildifier: disable=native-android
native.android_library(
name = "hilt-android",
exported_plugins = [
":hilt_dagger_compiler",
":hilt_android_entry_point_processor",
":hilt_aggregated_deps_processor",
":hilt_alias_of_processor",
":hilt_define_component_processor",
":hilt_generates_root_input_processor",
":hilt_originating_element_processor",
":hilt_root_processor",
":hilt_view_model_processor",
],
visibility = ["//visibility:public"],
exports = [
"%s//:com_google_dagger_dagger" % repo_name, # For Dagger APIs
"%s//:javax_inject_javax_inject" % repo_name, # For @Inject
"%s//:androidx_annotation_annotation" % repo_name, # For @CallSuper
"%s//:com_google_dagger_hilt_android" % repo_name,
"%s//:javax_annotation_jsr250_api" % repo_name, # For @Generated
],
)
# This target is same as dagger-compiler, but we're redefining it here
# so that users don't have to call dagger_rules() first.
native.java_plugin(
name = "hilt_dagger_compiler",
generates_api = 1,
processor_class = "dagger.internal.codegen.ComponentProcessor",
deps = [
"%s//:com_google_dagger_dagger_compiler" % repo_name,
],
)
native.java_plugin(
name = "hilt_android_entry_point_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.androidentrypoint.AndroidEntryPointProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_aggregated_deps_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.aggregateddeps.AggregatedDepsProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_alias_of_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.aliasof.AliasOfProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_define_component_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.definecomponent.DefineComponentProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_generates_root_input_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.generatesrootinput.GeneratesRootInputProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_originating_element_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.originatingelement.OriginatingElementProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_root_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.root.RootProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_view_model_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.viewmodel.ViewModelProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
# https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-android
# buildifier: disable=native-android
native.android_library(
name = "hilt-android-testing",
testonly = 1,
exported_plugins = [
":hilt_bind_value_processor",
":hilt_custom_test_application_processor",
":hilt_testroot_processor",
":hilt_uninstall_modules_processor",
],
visibility = ["//visibility:public"],
exports = [
":hilt-android",
"%s//:androidx_test_core" % repo_name, # For ApplicationProvider
"%s//:com_google_dagger_hilt_android_testing" % repo_name,
],
)
native.java_plugin(
name = "hilt_bind_value_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.bindvalue.BindValueProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_custom_test_application_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.customtestapplication.CustomTestApplicationProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_testroot_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.testroot.TestRootProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)
native.java_plugin(
name = "hilt_uninstall_modules_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.uninstallmodules.UninstallModulesProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)