I vaguely remember there being a way to assign to ...
# community-support
m
I vaguely remember there being a way to assign to a Property<String> with = in kotlin build scripts, but now can't find anything about that and gradle seems to be rejecting it with
[ASSIGNMENT_TYPE_MISMATCH] Assignment type mismatch: actual type is 'String', but 'Property<String>' was expected.
Is prop.set the only way to do this in current gradle versions?
e
it should just work in
*.gradle.kts
, or at least I don't see how you could end up in a situation where it doesn't work…
if you're writing a binary plugin, apply the
kotlin-dsl
plugin which enables the script-like syntax, or manually configure
Copy code
plugins {
    id("org.jetbrains.kotlin.plugin.assignment")
}

assignment {
    annotation("org.gradle.api.SupportsKotlinAssignmentOverloading")
}
and
import org.gradle.kotlin.dsl.assign
in your
.kt
source file
m
I figured it out, the fields had to be abstract instead of initialized with project.objects.propertyT()
e
on a
val
?
sounds like you may have been hitting an explicitly unsupported case https://github.com/gradle/KEEP/blob/assign-operator/proposals/assign-operator-overload.md
Assign operator overload should NOT work for var properties/variables. Setter resolution logic should always have a priority even if type doesn’t match.
also for future reference
org.gradle.kotlin.kotlin-dsl.compiler-settings
also applies
Copy code
plugins {
    id("org.jetbrains.kotlin.plugin.sam.with.receiver")
}
samWithReceiver {
    annotation("org.gradle.api.HasImplicitReceiver")
}