From 79886e7a5f07ec25399861c89561782967a40e49 Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Sun, 15 Jan 2023 11:16:50 +0000 Subject: [PATCH] Handle the case where a java rule produces more than one output --- private/rules/maven_bom_fragment.bzl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/private/rules/maven_bom_fragment.bzl b/private/rules/maven_bom_fragment.bzl index 9c3c2d263..8ac88c80b 100644 --- a/private/rules/maven_bom_fragment.bzl +++ b/private/rules/maven_bom_fragment.bzl @@ -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, @@ -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],