@@ -2,8 +2,9 @@ package org.sdkotlin.buildlogic.attributes
2
2
3
3
import org.gradle.api.attributes.AttributeDisambiguationRule
4
4
import org.gradle.api.attributes.MultipleCandidatesDetails
5
+ import org.gradle.api.model.ObjectFactory
5
6
import org.gradle.nativeplatform.OperatingSystemFamily
6
- import org.sdkotlin.buildlogic.attributes.CurrentOsAttributeDisambiguationRule.Companion.currentOsAttributeValue
7
+ import javax.inject.Inject
7
8
8
9
/* *
9
10
* A rule to disambiguate between multiple candidates of the
@@ -14,25 +15,20 @@ import org.sdkotlin.buildlogic.attributes.CurrentOsAttributeDisambiguationRule.C
14
15
* object property [currentOsAttributeValue] during the project configuration
15
16
* phase. This value is then used to determine the closest match among the
16
17
* 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].
17
22
*/
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> {
32
26
33
27
override fun execute (
34
28
details : MultipleCandidatesDetails <OperatingSystemFamily >
35
29
) {
36
- details.closestMatch(currentOsAttributeValue)
30
+ if (details.candidateValues.contains(currentOsAttribute)) {
31
+ details.closestMatch(currentOsAttribute)
32
+ }
37
33
}
38
34
}
0 commit comments