In a `Task`, what would be the right way to check ...
# community-support
z
In a
Task
, what would be the right way to check if a configuration contains a specific local
ProjectDependency
? I want to write a verification task that fails the build if that
Configuration
contains a subproject we don't publish externally
m
Wild guess:
Copy code
configuration.dependencies.any { it is ProjectDependency && it.dependencyProject.path == ":foo" }
v
Not if it should be CC compatible
Or also match transitively
m
Yea, was going to say, this is only the direct dependencies
Looks like you need to resolve the configuration
v
You probably would use an artifact view with a component filter, give that result in a CC compatible way to the task and then check whether it is empty at execution time or something like that
m
Best I've got so far:
Copy code
val allGood: Provider<Boolean> = configuration.incoming.resolutionResult.rootComponent.map {
  it.dependencies.any {
    (it is ResolvedDependencyResult) && (it.selected.id as? ProjectComponentIdentifier)?.projectPath?.contains("foobar") == true
  }
}
(edited to make it a bit more compact but can't beat the artifactView)
v
Not tested but roughly what I meant:
Copy code
val allGood: Provider<Boolean> = configuration.incoming.artifactView {
    componentFilter {
        (it is ProjectComponentIdentifier) && (it.projectPath == ":what:ever")
    }
}.artifacts.resolvedArtifacts.map { it.isEmpty() }