Can I apply ksp gradle plugin from my own gradle p...
# ksp
r
Can I apply ksp gradle plugin from my own gradle plugin?
j
yes you should be able
r
I've tried
project.pluginManager.apply("com.google.devtools.ksp")
and it does seem to work without errors, but not fully correct (some tasks are missing and I can't apply ksp to my mpp targets).
j
which errors and how are you applying your plugin
r
My plugin is applied with
plugins { id("...") }
block
j
there should be no difference between that and applying ksp directly
if you are using the same version and so on
r
E.g. when applying directly I see three tasks:
Copy code
kspCommonMainKotlinMetadata
kspKotlinBackend
kspKotlinFrontend
but when applying indirectly I see only one of them:
kspKotlinFrontend
j
maybe you are combining your plugins in your convention plugin in a way it is not detecting that kmp is enabled or something so
you can confirm that by having the same setup and only applying ksp in your convention plugin
r
When applying directly it works:
Copy code
dependencies {
    add("kspCommonMainMetadata", "myprocessor")
    add("kspFrontend", "myprocessor")
}
j
I have seen issues with plugin orders before with Kotlin Gradle plugin for example
r
When indirectly I have an error:
Copy code
> Configuration with name 'kspFrontend' not found.
j
kmp plugin is applied by your convention plugin too?
or directly
r
The same setup - I've just commented
id("com.google.devtools.ksp") version "1.7.0-1.0.6"
in my
plugins {}
block
j
that is weird
r
kotlin plugin is applied directly
j
check if the kgp/ksp versions are correct
maybe it is taking a different version from the classpath
r
I'll try to check this configuration step by step once again - perhaps I'm missing something obvious
j
you convention plugin is a precompiled one?
r
yes
j
apply ksp in the plugins block in your precompiled plugin instead of with the manager
r
I've managed to make it work. I've applied the plugin with
plugins.apply("com.google.devtools.ksp")
line and then applied it to my source sets with:
Copy code
dependencies {
            add("kspCommonMainMetadata", "myprocessor")
        }

        afterEvaluate {
            dependencies {
                add("kspFrontend", "myprocessor")
            }
        }
j
I would apply the plugins in the plugins block in precompiled plugins instead of with apply
r
I have no idea why common can't be in the
afterEvaluate
block as well and why
kspFrontend
needs to (doesn't work without it)
Tried with the plugins block but it doesn't work (or I don't know how to do it 😉)
j
that is weird
is your project open source?
r
Yes. But it's quite large and complicated (KVision).
j
is there a branch where you are trying these things?
r
I'll publish the branch in a moment
👍 1
my plugin and processor are in the kvision-tools dir
This is currently working fine for me but I'll be grateful for any advice how to make it better :)
j
where is the precompiled plugin??
I think we missunderstood
I was thinking you had a precompiled convention plugin, but looks like it is a normal convention plugin
r
Yep, I have a normal plugin not a precompiled one. Sorry for misleading. I'v just googled what a precompiled gradle plugin is 😉
👍 1