CodexBloom - Programming Q&A Platform

Kotlin DSL not correctly resolving type inference with custom property extensions in Gradle build scripts

πŸ‘€ Views: 459 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-14
kotlin gradle kotlin-dsl Kotlin

I tried several approaches but none seem to work. I'm working with a frustrating scenario with Kotlin DSL in my Gradle build scripts. I have defined some custom property extensions for configuring library dependencies, but the type inference seems to unexpected result in certain scenarios, generating a compilation behavior. Here’s a simplified version of my code: ```kotlin // build.gradle.kts val DependencyHandlerScope.myLib: String get() = "com.example:my-library:1.0.0" dependencies { implementation(myLib) } ``` When I run the build, I receive the following behavior message: ``` Unresolved reference: myLib ``` I’ve tried cleaning the project and invalidating the caches, but the behavior continues. I also confirmed that this works perfectly in Java-based Gradle scripts. I'm using Kotlin 1.6.10 and Gradle 7.3.3. I suspect it might be an scenario with how the Kotlin DSL resolves types for custom extensions. Has anyone faced this scenario or has any insight into how to properly configure custom properties in a Kotlin DSL context? How would you solve this?