Skip to content

Commit

Permalink
improve extendsFromFlattened utility
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 31, 2024
1 parent da4799b commit 24541bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/kotlin/org/incendo/cloudbuildlogic/util/configurations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ package org.incendo.cloudbuildlogic.util

import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.project
import org.incendo.cloudbuildlogic.coordinates
import org.incendo.cloudbuildlogic.moduleComponentId

/**
* When [includeProjectDependencies] is false, project dependencies will be excluded,
* but their transitive dependencies will not be.
*/
fun Configuration.extendsFromFlattened(
other: NamedDomainObjectProvider<Configuration>,
dependencyHandler: DependencyHandler,
includeProjectDependencies: Boolean = false,
) {
defaultDependencies {
for (artifact in other.get().incoming.artifacts.artifacts) {
if (includeProjectDependencies && artifact.id.componentIdentifier is ProjectComponentIdentifier) {
val projectId = artifact.id.componentIdentifier as ProjectComponentIdentifier
add(dependencyHandler.project(projectId.projectPath))
continue
}
val id = artifact.moduleComponentId() ?: continue
add(dependencyHandler.create(coordinates(id)))
}
Expand Down

0 comments on commit 24541bf

Please sign in to comment.