Skip to content

Commit 70e74bb

Browse files
committed
[bazel] Allow classifiers in maven coordinates
1 parent 620d0fb commit 70e74bb

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

java/private/common.bzl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,22 @@ def combine_jars(ctx, singlejar, inputs, output):
9898

9999
def explode_coordinates(coords):
100100
"""Takes a maven coordinate and explodes it into a tuple of
101-
(groupId, artifactId, version, type)
101+
(groupId, artifactId, version, type, classifier)
102102
"""
103103
if not coords:
104104
return None
105105

106106
parts = coords.split(":")
107107
if len(parts) == 3:
108-
return (parts[0], parts[1], parts[2], "jar")
108+
return (parts[0], parts[1], parts[2], "jar", "jar")
109109
if len(parts) == 4:
110110
# Assume a buildr coordinate: groupId:artifactId:type:version
111-
return (parts[0], parts[1], parts[3], parts[2])
111+
return (parts[0], parts[1], parts[3], parts[2], "jar")
112+
if len(parts) == 5:
113+
# Assume groupId:artifactId:type:classifier:version
114+
return (parts[0], parts[1], parts[4], parts[2], parts[3])
112115

113-
fail("Unparsed: %s" % coords)
116+
fail("Unparsed: %s -> %s" % (coords, parts))
114117

115118
def read_coordinates(tags):
116119
coordinates = []

java/private/pom.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ _TYPED_DEP = """ <dependency>
1919
<type>{3}</type>
2020
</dependency>"""
2121

22+
_CLASSIFIER_DEP = """ <dependency>
23+
<groupId>{0}</groupId>
24+
<artifactId>{1}</artifactId>
25+
<version>{2}</version>
26+
<classifier>{4}</classifier>
27+
</dependency>"""
28+
2229
def _pom_file_impl(ctx):
2330
# Ensure the target has coordinates
2431
if not ctx.attr.target[MavenInfo].coordinates:
@@ -34,15 +41,19 @@ def _pom_file_impl(ctx):
3441
"{artifactId}": coordinates[1],
3542
"{version}": coordinates[2],
3643
"{type}": coordinates[3],
44+
"{classifier}": coordinates[4],
3745
}
3846

3947
deps = []
4048
for dep in sorted(info.maven_deps.to_list()):
4149
exploded = explode_coordinates(dep)
42-
if (exploded[3] == "jar"):
50+
if (exploded[4] != "jar"):
51+
template = _CLASSIFIER_DEP
52+
elif (exploded[3] == "jar"):
4353
template = _PLAIN_DEP
4454
else:
4555
template = _TYPED_DEP
56+
4657
deps.append(template.format(*exploded))
4758
substitutions.update({"{dependencies}": "\n".join(deps)})
4859

0 commit comments

Comments
 (0)