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 bd84d0ce..fea0c035 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 @@ -8,9 +8,7 @@ import io.github.sgtsilvio.gradle.oci.attributes.* import io.github.sgtsilvio.gradle.oci.component.* import io.github.sgtsilvio.gradle.oci.dsl.OciImageDefinition import io.github.sgtsilvio.gradle.oci.internal.* -import io.github.sgtsilvio.gradle.oci.internal.gradle.LazyPublishArtifact -import io.github.sgtsilvio.gradle.oci.internal.gradle.addArtifacts -import io.github.sgtsilvio.gradle.oci.internal.gradle.zipAbsentAsNull +import io.github.sgtsilvio.gradle.oci.internal.gradle.* import io.github.sgtsilvio.gradle.oci.mapping.defaultMappedImageNamespace import io.github.sgtsilvio.gradle.oci.metadata.OciImageReference import io.github.sgtsilvio.gradle.oci.platform.AllPlatformFilter @@ -99,13 +97,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( } 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 + project.createDependency().requireCapabilities(capabilities) } final override fun getName() = name @@ -531,13 +523,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( } fun createDependency(): Provider = providerFactory.provider { - val projectDependency = project.dependencies.create(project) as ProjectDependency - projectDependency.capabilities { - for (capability in configuration.outgoing.capabilities) { - requireCapability("${capability.group}:${capability.name}") - } - } - projectDependency + project.createDependency().requireCapabilities(configuration.outgoing.capabilities) } } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt index 57d59be2..933a822e 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt @@ -1,6 +1,7 @@ package io.github.sgtsilvio.gradle.oci.internal.dsl import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependencies +import io.github.sgtsilvio.gradle.oci.internal.gradle.createDependency import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.artifacts.* @@ -50,16 +51,15 @@ internal abstract class OciImageDependenciesImpl( private fun module(dependencyNotation: CharSequence) = dependencyHandler.create(dependencyNotation) as ExternalModuleDependency - private fun project(project: Project) = dependencyHandler.create(project) as ProjectDependency - final override fun add(dependencyNotation: CharSequence) = add(module(dependencyNotation)) final override fun add(dependencyNotation: CharSequence, action: Action) = add(module(dependencyNotation), action) - final override fun add(project: Project) = add(project(project)) + final override fun add(project: Project) = add(project.createDependency()) - final override fun add(project: Project, action: Action) = add(project(project), action) + final override fun add(project: Project, action: Action) = + add(project.createDependency(), action) // add constraint diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt index e36aaf5d..0bd516ca 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt @@ -10,6 +10,7 @@ import io.github.sgtsilvio.gradle.oci.component.resolveOciImageSpecs import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Nameable import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Taggable +import io.github.sgtsilvio.gradle.oci.internal.gradle.attribute import io.github.sgtsilvio.gradle.oci.internal.gradle.zipAbsentAsNull import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.ModuleDependency @@ -88,9 +89,7 @@ internal abstract class ResolvableOciImageDependenciesImpl @Inject constructor( final override fun addInternal(dependency: ModuleDependency): ReferenceSpecBuilder { val referenceSpecBuilder = ReferenceSpecBuilder(objectFactory) configuration.dependencies.addLater(referenceSpecBuilder.attribute.map { attribute -> - dependency.attributes { - attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute) - } + dependency.attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute) }) return referenceSpecBuilder } @@ -98,9 +97,7 @@ internal abstract class ResolvableOciImageDependenciesImpl @Inject constructor( final override fun addInternal(dependencyProvider: Provider): ReferenceSpecBuilder { val referenceSpecBuilder = ReferenceSpecBuilder(objectFactory) configuration.dependencies.addLater(dependencyProvider.zip(referenceSpecBuilder.attribute) { dependency, attribute -> - dependency.attributes { - attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute) - } + dependency.attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute) }) return referenceSpecBuilder } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/gradle/DependencyFactories.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/gradle/DependencyFactories.kt new file mode 100644 index 00000000..b593c1b3 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/gradle/DependencyFactories.kt @@ -0,0 +1,25 @@ +package io.github.sgtsilvio.gradle.oci.internal.gradle + +import org.gradle.api.Project +import org.gradle.api.artifacts.ModuleDependency +import org.gradle.api.artifacts.ProjectDependency +import org.gradle.api.attributes.Attribute +import org.gradle.api.capabilities.Capability + +internal fun Project.createDependency() = project.dependencies.create(project) as ProjectDependency + +internal fun T.requireCapabilities(capabilities: Iterable): T { + capabilities { + for (capability in capabilities) { + requireCapability("${capability.group}:${capability.name}") + } + } + return this +} + +internal fun T.attribute(key: Attribute, value: A): T { + attributes { + attribute(key, value) + } + return this +}