Hi there,
I’ve created a binary plugin written entirely in kotlin and the experience has been great, other than one detail: I can’t seem to get anything other than the conventional value out of my extension object no matter what approach I try.
In unit tests I can directly modify the value of the extension without any issue, it just refuses to take anything from the build file DSL. I’ve tried cribbing from many extant examples on github.
Clearly I’m doing something wrong, but the documentation isn’t any help in this regard, can someone point me in the right direction?
Example plugin code:
const val EXTENSION_NAME = "myPlugin"
open class MyExtension @Inject internal constructor(objectFactory: ObjectFactory) {
val myProp: Property<String> = objectFactory.property(String::class.java).convention("")
}
class MyPlugin : Plugin<Project> {
override fun apply(project: Project): Unit =
project.run {
val extension = project.extensions.create(
EXTENSION_NAME,
MyExtension::class.java,
project.objects,
)
logger.debug("myProp: {}", extension.myProp.get())
}
}
Example build file:
plugins {
id ("myorg.my-plugin") version "0.1.0"
}
myPlugin {
myProp.set("WORKING")
}
Example output
2025-10-31T15:11:41.014+0000 [DEBUG] [org.gradle.api.Project] myProp:
Thanks.