What I want to achieve: I want to import material3 library into Gradle Kotlin-DSL implementation.
What I've tried:
I've tried importing it as the rest of imports in the plugin. Below is my plugin implementation
AndroidLibraryComposeConventionPlugin.kt
class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.android.library")
val extension = extensions.getByType<LibraryExtension>()
configureAndroidCompose(extension)
}
}
}
And in libs.versions.toml I have declared material3 dependency as following:
[libraries]
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
But when I try to add this in the plugin as following:
"implementation"(libs.findLibrary("androidx-compose-material3").get())
or
add("implementation", libs.findLibrary("androidx-compose-material3").get())
I get an error that this dependency cannot be found.
libs is an extension created for this project and looks as following:
val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
Implementing it in plugin is crucial for me as I want to delegate importing dependencies to plugin, not build.gradle.kts itself.
The reason is wasn't working was because material3 library in libs.versions.toml wasn't specified. That's weird behaviour, as I had compose BOM implemented, therefore version shouldn't be necessary to specify. I've reported issue to Google, maybe it's their fault.