```androidComponets { onVariants { pri...
# gradle
u
Copy code
androidComponets {
    onVariants {
        println "variant=$it"
    }
}

why does this not compile? its eaxcly the official sample
e
pretty sure
onVariants
is AGP 7.0+
u
Yea I know, still nothing
v
Probably the missing
n
in components
👍 1
u
🤦🤦🤦🤦🤦🤦🤦😂 im so sorry guys
Anyways, that was stupid, but it still doesnt work
Copy code
androidComponents {
    onVariants { variant ->
        println "variant=$variant"
    }
}
Copy code
* Where:
Build file 'C:\Misc\mo2-android\tesco-mobile\app\build.gradle' line: 162

* What went wrong:
A problem occurred evaluating project ':tesco-mobile:app'.
> No signature of method: build_7qrc4nz4nypxqatfu7rooj9dy.androidComponents() is applicable for argument types: (build_7qrc4nz4nypxqatfu7rooj9dy$_run_closure2) values: [build_7qrc4nz4nypxqatfu7rooj9dy$_run_closure2@3d15c5c7]
the 162 is the androidComponents line https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/extension/AndroidComponentsExtension#onvariants AGP 7.0.0-beta05 Should work, right?
After some trial and error, this works
Copy code
androidComponents {
    onVariants(selector().all()) { variant ->
        println "variant=$variant"
    }
}
but why? the function has it as a default param, so I should be able to call it paramless on my end? is this a groovy thing?
anyways, my point of messing with the variants api was configuration avoidance, and it still prints when running
gradlew help
so I guess its just syntactic sugar 😕
v
Groovy has method parameters with default values and Kotlin too. But if the class is written in Kotlin, the Kotlin Java interop applies. So to quote https://kotlinlang.org/docs/java-to-kotlin-interop.html#overloads-generation:
Normally, if you write a Kotlin function with default parameter values, it will be visible in Java only as a full signature, with all parameters present. If you wish to expose multiple overloads to Java callers, you can use the @JvmOverloads annotation.
So when calling a Kotlin function with default parameters, you have to provide all arguments. If the developers would be nice and honor that a usage from Groovy is likely for a Gradle plugin, they could add that annotation so that the overloads are generated.
u
ill open a bug with them thanks!
👌 1