# Simpler Kotlin DSL Property Assignment

DevFeed: [Simpler Kotlin DSL Property Assignment](<https://devfeed.tech/articles/simpler-kotlin-dsl-property-assignment-24691.md>)

Original publisher: [Read original article](<https://blog.gradle.org/simpler-kotlin-dsl-property-assignment>)

Author: Anže Sodja

Published: 2023-06-30T04:00:00Z

Content type: article

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [API](<https://devfeed.tech/topics/api.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [declarative](<https://devfeed.tech/tags/declarative.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [improvements](<https://devfeed.tech/tags/improvements.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

## AI overview

This article explains Gradle's lazy property API and the simpler Kotlin DSL assignment syntax introduced in Gradle 8.2. The new operator-based syntax reduces verbosity, improves declarative configuration, and makes migration from Groovy DSL to Kotlin DSL easier.

## Source excerpt

One of the improvements that made making Kotlin DSL the default for new Gradle builds possible was a simpler way to assign values with lazy properties. In this blog post, we will explain what lazy property assignment is and how you can take advantage of the new syntax in the latest Gradle release. What is the lazy property API? The lazy property API is a Gradle feature that delays the calculation of a property's value until its required. This is the recommended way of writing properties for extensions and tasks. Some of the provided benefits include: Solving configuration ordering issues (no more Project.afterEvaluate()) Tracking dependencies automatically (no need for Task.dependsOn()) Providing standardized access (no custom behavior in setters or getters) Reducing boilerplate for property declarations (no field and a setter, just a getter) To use the lazy property API in a custom task, you replace primitive types with a property type. e.g., abstract class MyTask : DefaultTask() { @get:Input var myProperty: String? = null @TaskAction fun run() { // Skipped for brevity } } Becomes: abstract class MyTask : DefaultTask() { @get:Input abstract val myProperty: Property<String> @TaskAction fun run() { // Skipped for brevity } } Here comes trouble! While lazy properties provide several benefits, they may make configuring properties with the Kotlin DSL a bit verbose. In Groovy DSL, lazy properties can be assigned with a simple =: tasks.register("taskName", MyTask) { myProperty = "Constant string value" } However, in Kotlin DSL, assigning a value to a property required the use of a verbose set(...) method: tasks.register<MyTask>("taskName") { myProperty.set("Constant string value") } Users have clearly wanted a simpler syntax that looked more declarative. The request for a concise and statically typed Property<T> assignment is one of the most highly voted GitHub issues. As the Kotlin language did not support overloading the assign operator, there were not many good choices t