From c98362c8e339caaf1c5e5613e35bb249831105e6 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Sat, 16 Mar 2024 13:57:28 +0100 Subject: [PATCH] Fix eager evaluation of image definition capabilities for OciPushSingleTask --- .../io/github/sgtsilvio/gradle/oci/OciPlugin.kt | 8 +------- .../sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt | 2 ++ .../oci/internal/dsl/OciImageDefinitionImpl.kt | 12 ++++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt index 54941899..64ae7488 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt @@ -28,13 +28,7 @@ class OciPlugin : Plugin { val pushName = "push".concatCamelCase(name.mainToEmpty()) val pushTask = project.tasks.register(pushName.concatCamelCase("ociImage")) val pushImageDependencies = extension.imageDependencies.create(pushName) { - add(project) { - capabilities { - for (capability in capabilities.set.get()) { - requireCapability("${capability.group}:${capability.name}") - } - } - }.name(pushTask.flatMap { it.imageName }).tag(pushTask.flatMap { it.imageTags }) + add(dependency).name(pushTask.flatMap { it.imageName }).tag(pushTask.flatMap { it.imageTags }) } pushTask { group = TASK_GROUP_NAME diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt index b48adb8d..d3438a2e 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt @@ -8,6 +8,7 @@ import io.github.sgtsilvio.gradle.oci.platform.PlatformFilter import org.gradle.api.Action import org.gradle.api.Named import org.gradle.api.NamedDomainObjectList +import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.capabilities.Capability import org.gradle.api.provider.* import org.gradle.api.tasks.TaskProvider @@ -19,6 +20,7 @@ interface OciImageDefinition : Named { val capabilities: Capabilities val indexAnnotations: MapProperty val component: Provider + val dependency: Provider fun capabilities(configuration: Action) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt index 7bb661b5..f82cae54 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt @@ -23,6 +23,7 @@ import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.ModuleDependency +import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.attributes.Bundling import org.gradle.api.attributes.Category @@ -65,6 +66,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( private var platformBundles: TreeMap? = null final override val component = createComponent(providerFactory) private val componentTask = createComponentTask(name, taskContainer, projectLayout) + final override val dependency = createDependency() init { registerArtifacts(objectFactory, providerFactory) @@ -123,6 +125,16 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( classifier.set(createOciComponentClassifier(imageDefName)) } + private fun createDependency(): Provider = capabilities.set.map { capabilities -> + val projectDependency = project.dependencies.create(project) as ProjectDependency + projectDependency.capabilities { + for (capability in capabilities) { + requireCapability("${capability.group}:${capability.name}") + } + } + projectDependency + } + private fun registerArtifacts(objectFactory: ObjectFactory, providerFactory: ProviderFactory) { imageConfiguration.outgoing.addArtifacts(providerFactory.provider { val layerTasks = LinkedHashMap>()