Mapping Extension Properties to Tasks in kotlin-ds...
# gradle
d
Mapping Extension Properties to Tasks in kotlin-dsl. I am attempting to implement an extension property as the default for a task property by following the example in kotlin-dsl/samples/provider-properties. Mostly working -- in a groovy build script It 'works' however in a kotlin build script the property ( Property<String>) seems directly exposed -- I need to write property.set("value") instead of property = "value" Example: In extension Object: val bucket = project.objects.property<String>() In Task: open class CreatePackageTask : AbstractExecTask<CreatePackageTask>(CreatePackageTask::class.java) { ... @get:Input val bucket = project.objects.property<String>() .... @TaskAction override fun exec() : Unit { val bucket = bucket.get() .... Registering Task (in plugin.gradle.kts) tasks { register("createPackage", CreatePackageTask::class){ group = "cloud" bucket.set(cloud.bucket) ... So far so good ... but in the calling buildscript: groovy: (build.gradle) cloud { bucket = "bucket" // 'just works' kotlin: (build.gradle.kts) cloud { bucket = "bucket" // ERROR val cannot be reassigned , ERROR Inferred type is String but expected type is Property<String> ... this works -> bucket.set("bucket") --> What is the correct way to get the last case to work ? Thinking of instead a 'var' and overriding 'set(value: String)' This worked: Adding -> public fun setBucket(_bucket : String) { bucket.set(_bucket) } Seems pretty hacky .. (and would need be done for all properties). Any recomendations ?