This message was deleted.
# dependency-management
s
This message was deleted.
v
This seems to be the way:
Copy code
configurations.runtimeClasspath.flatMap {
    it.incoming.artifacts.resolvedArtifacts.map {
        it.filter {
            it.variant.attributes.getAttribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE) != null
        }.map {
            it.file
        }
    }
}
Yeah, no, not fully. The problem is, that attributes coming from a
@CachedRule
and attributes coming from module metadata file are primitve and not longer typed. So you have to check for actual
OPERATING_SYSTEM_ATTRIBUTE
attribute and a
String
typed version of it, or get the attribute keys and match by name.
So you probably need something like this instead:
Copy code
configurations.runtimeClasspath.flatMap {
    it.incoming.artifacts.resolvedArtifacts.map { artifactResults ->
        artifactResults.filter { artifactResult ->
            val variantAttributes = artifactResult.variant.attributes
            variantAttributes
                .keySet()
                .filter { it.name == OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE.name }
                .also {
                    if (it.size > 1) {
                        throw AssertionError("Multiple attributes with same name are not expected")
                    }
                }
                .singleOrNull()
                ?.let { variantAttributes.getAttribute(it) }
                ?.takeIf {
                    (it is OperatingSystemFamily) || (it is String)
                } != null
        }.map { artifactResult ->
            artifactResult.file
        }
    }
}
m
yes, horrible code, I have something similar
(in Java, because nobody needs Kotlin in plugins ;))
v
I fully agree for plugins that should be compatible with multiple Gradle versions. For plugins local to a build or cofined to a specific Gradle version I prefer the nicety of Kotlin 🙂
m
nevertheless, I apologize for that API, because I participated in it. For my defense I wanted the strongly typed to be removed because of these practical issues, but lost the battle 🙂
v
sad panda