Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare kotlin Compiler Extension version using version catalog file

I migrated my Gradle to Version Catalog and I want to move the Kotlin compose compiler to the libs.versions.toml as well.

This is my current declaration in the Gradle App:

composeOptions {
    kotlinCompilerExtensionVersion = "1.5.11"
}

I tried to do it like this

libs.versions.toml

[versions]
kotlinComposeCompiler = "1.5.11"

build.gradle.kts (:app)

composeOptions {
    kotlinCompilerExtensionVersion = "${libs.versions.kotlinComposeCompiler}"
}

But my project sometimes doesn't sync with this error:

Could not find androidx.compose.compiler:compiler:provider(?).

What is the correct way to declare Kotlin Compiler Extension version using version catalog

like image 519
Roman Avatar asked Aug 31 '25 16:08

Roman


1 Answers

It looks like you've set up the version catalog correctly. This generates some code including a property libs.versions.kotlinComposeCompiler which is of type Provider<String> (click on it in your IDE to take a look).

Provider is a Gradle type which is a wrapper around the version designed to help with lazy initialisation, though that is not applicable here.

To get the String version you need from inside the Provider, you simply call get() on it, so you end up with:

composeOptions {
    kotlinCompilerExtensionVersion = libs.versions.kotlinComposeCompiler.get()
}
like image 173
Simon Jacobs Avatar answered Sep 02 '25 06:09

Simon Jacobs