Keep default value of task property

Like this:

abstract class AppExtension(
    val mainClass: Property<String>
) {
    abstract val name: Property<String>
    abstract val fileName: Property<String>
}

val bootJar by tasks.getting(BootJar::class)
val app = extensions.create<AppExtension>("app", bootJar.mainClass).apply {
    name.convention(project.provider { project.name })
    fileName.convention(project.provider { "${project.name}.jar" })
}

The caveat it has is, that if someone modifies the property on the BootJar task it will also modify the one on the extension of course as they are the same now. If that is ok for you, that’s probably the way to go and much better than using afterEvaluate.

1 Like