Guilherme Delgado
11/03/2022, 12:03 PMwith(pluginManager) {
apply("com.android.library")
apply("com.google.devtools.ksp")
}
but it always fails saying it cant be found. If i add it like this (in the build.gradle):
plugins {
alias(libs.plugins.ksp)
}
it works. Am i missing any syntax? I’ve tried also like this:
val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
with(pluginManager) {
apply("com.android.library")
apply("com.google.devtools.ksp:${catalog.findVersion("gradleGoogleKsp").get()}")
}
But with no luck 🤔Vampire
11/03/2022, 1:43 PMpluginManager
, you can directly call apply
or even better you should use the plugins { ... }
block in your convention plugin.
Do you have a dependency on the plugin you try to apply in the build script of the project that builds your convention plugin?Guilherme Delgado
11/03/2022, 1:48 PMclass MyPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
with(pluginManager) {
apply("com.android.library")
apply("com.google.devtools.ksp")//:${catalog.findVersion("gradleGoogleKsp").get()}")
}
extensions.configure<LibraryExtension> { addVariantOptions() }
dependencies {
add("implementation", catalog.findLibrary...)
add("ksp", catalog.findLibrary...)
}
}
}
private fun LibraryExtension.addVariantOptions() {
apply {
libraryVariants.all {
sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
}
}
}
Guilherme Delgado
11/03/2022, 1:49 PMplugins {
id("buildlogic.plugins.myplugin")
// alias(libs.plugins.ksp)
}
Guilherme Delgado
11/03/2022, 1:50 PMwith(pluginManager)
with with(plugins)
? It throws the same error 😞Vampire
11/03/2022, 3:41 PMapply
method of course, but you can just use
apply("com.android.library")
apply("com.google.devtools.ksp")
instead of
with(pluginManager) {
apply("com.android.library")
apply("com.google.devtools.ksp")
}
as Project
is PluginAware
.
It is not wrong, just unnecessary boilerplate.
plugins
should actually never be used according to its JavaDoc.
But of course it throws the same error.
As I said, you need to add the plugin as implementation
dependency to the project building that convention plugin or the plugin is not on the class path and cannot be found.Guilherme Delgado
11/03/2022, 3:53 PM