Skip to content

Commit

Permalink
Handle the case where a java rule produces more than one output
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jan 15, 2023
1 parent c6800c4 commit 79886e7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions private/rules/maven_bom_fragment.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ MavenBomFragmentInfo = provider(
)

def _maven_bom_fragment_impl(ctx):
java_info = ctx.attr.artifact[JavaInfo]

# Recent Bazel versions
if "output_jar" in dir(java_info):
artifact_jar = java_info["output_jar"]
elif len(java_info.outputs.jars):
artifact_jar = java_info.outputs.jars[0]
if len(java_info.outputs.jars) > 1:
print("Maven BOM may not be correct. Expected one jar, got %s for %s" % (len(java_info.outputs.jars), ctx.label))
else:
artifact_jar = None

return [
MavenBomFragmentInfo(
coordinates = ctx.attr.maven_coordinates,
artifact = ctx.file.artifact,
artifact = artifact_jar,
srcs = ctx.file.src_artifact,
javadocs = ctx.file.javadoc_artifact,
pom = ctx.file.pom,
Expand All @@ -32,7 +44,6 @@ maven_bom_fragment = rule(
),
"artifact": attr.label(
doc = """The `maven_project_jar` that forms the primary artifact of the maven coordinates""",
allow_single_file = True,
mandatory = True,
providers = [
[JavaInfo],
Expand Down

0 comments on commit 79886e7

Please sign in to comment.