From 8322dda8cc06e34b5239f8343fbda9214cf0f655 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 1 Dec 2021 12:16:14 +0000 Subject: [PATCH] Fix variant selection in spring-boot-maven-plugin See gh-28877 --- .../boot/build/mavenplugin/MavenPluginPlugin.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java index d86814a818..18fcffb493 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java @@ -38,6 +38,7 @@ import org.gradle.api.artifacts.VariantMetadata; import org.gradle.api.artifacts.component.ModuleComponentIdentifier; import org.gradle.api.artifacts.result.ResolvedArtifactResult; import org.gradle.api.attributes.DocsType; +import org.gradle.api.attributes.Usage; import org.gradle.api.file.CopySpec; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.model.ObjectFactory; @@ -296,13 +297,16 @@ public class MavenPluginPlugin implements Plugin { public void execute(ComponentMetadataContext context) { context.getDetails().maybeAddVariant("compileWithMetadata", "compile", (variant) -> configureVariant(context, variant)); - context.getDetails().maybeAddVariant("runtimeElementsWithMetadata", "runtimeElements", + context.getDetails().maybeAddVariant("apiElementsWithMetadata", "apiElements", (variant) -> configureVariant(context, variant)); } private void configureVariant(ComponentMetadataContext context, VariantMetadata variant) { - variant.attributes((attributes) -> attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, - this.objects.named(DocsType.class, "maven-repository"))); + variant.attributes((attributes) -> { + attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, + this.objects.named(DocsType.class, "maven-repository")); + attributes.attribute(Usage.USAGE_ATTRIBUTE, this.objects.named(Usage.class, "maven-repository")); + }); variant.withFiles((files) -> { ModuleVersionIdentifier id = context.getDetails().getId(); files.addFile(id.getName() + "-" + id.getVersion() + ".pom");