@@ -2,8 +2,9 @@ package org.sdkotlin.buildlogic.attributes
22
33import org.gradle.api.attributes.AttributeDisambiguationRule
44import org.gradle.api.attributes.MultipleCandidatesDetails
5+ import org.gradle.api.model.ObjectFactory
56import org.gradle.nativeplatform.OperatingSystemFamily
6- import org.sdkotlin.buildlogic.attributes.CurrentOsAttributeDisambiguationRule.Companion.currentOsAttributeValue
7+ import javax.inject.Inject
78
89/* *
910 * A rule to disambiguate between multiple candidates of the
@@ -14,25 +15,20 @@ import org.sdkotlin.buildlogic.attributes.CurrentOsAttributeDisambiguationRule.C
1415 * object property [currentOsAttributeValue] during the project configuration
1516 * phase. This value is then used to determine the closest match among the
1617 * provided candidates during dependency resolution.
18+ *
19+ * @param currentOsAttributeValue the [OperatingSystemFamily] attribute value corresponding
20+ * to the current operating system.
21+ * @param objects the Gradle [ObjectFactory].
1722 */
18- open class CurrentOsAttributeDisambiguationRule :
19- AttributeDisambiguationRule <OperatingSystemFamily > {
20-
21- companion object {
22-
23- /* *
24- * Represents the [OperatingSystemFamily] attribute value corresponding
25- * to the current operating system. This variable must be initialized
26- * during the Gradle project configuration phase to ensure that
27- * dependency resolution prioritizes candidates that match the current
28- * operating system's attribute.
29- */
30- lateinit var currentOsAttributeValue: OperatingSystemFamily
31- }
23+ open class CurrentOsAttributeDisambiguationRule @Inject constructor(
24+ private val currentOsAttribute : OperatingSystemFamily ,
25+ ) : AttributeDisambiguationRule<OperatingSystemFamily> {
3226
3327 override fun execute (
3428 details : MultipleCandidatesDetails <OperatingSystemFamily >
3529 ) {
36- details.closestMatch(currentOsAttributeValue)
30+ if (details.candidateValues.contains(currentOsAttribute)) {
31+ details.closestMatch(currentOsAttribute)
32+ }
3733 }
3834}
0 commit comments