https://kotlinlang.org logo
#ksp
Title
# ksp
r

Robert Jaros

06/19/2022, 5:17 PM
Can I apply ksp gradle plugin from my own gradle plugin?
j

Javier

06/19/2022, 5:47 PM
yes you should be able
r

Robert Jaros

06/19/2022, 5:50 PM
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

Javier

06/19/2022, 5:51 PM
which errors and how are you applying your plugin
r

Robert Jaros

06/19/2022, 5:51 PM
My plugin is applied with
plugins { id("...") }
block
j

Javier

06/19/2022, 5:52 PM
there should be no difference between that and applying ksp directly
if you are using the same version and so on
r

Robert Jaros

06/19/2022, 5:53 PM
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

Javier

06/19/2022, 5:53 PM
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

Robert Jaros

06/19/2022, 5:55 PM
When applying directly it works:
Copy code
dependencies {
    add("kspCommonMainMetadata", "myprocessor")
    add("kspFrontend", "myprocessor")
}
j

Javier

06/19/2022, 5:56 PM
I have seen issues with plugin orders before with Kotlin Gradle plugin for example
r

Robert Jaros

06/19/2022, 5:56 PM
When indirectly I have an error:
Copy code
> Configuration with name 'kspFrontend' not found.
j

Javier

06/19/2022, 5:57 PM
kmp plugin is applied by your convention plugin too?
or directly
r

Robert Jaros

06/19/2022, 5:57 PM
The same setup - I've just commented
id("com.google.devtools.ksp") version "1.7.0-1.0.6"
in my
plugins {}
block
j

Javier

06/19/2022, 5:57 PM
that is weird
r

Robert Jaros

06/19/2022, 5:57 PM
kotlin plugin is applied directly
j

Javier

06/19/2022, 6:01 PM
check if the kgp/ksp versions are correct
maybe it is taking a different version from the classpath
r

Robert Jaros

06/19/2022, 6:02 PM
I'll try to check this configuration step by step once again - perhaps I'm missing something obvious
j

Javier

06/19/2022, 6:03 PM
you convention plugin is a precompiled one?
r

Robert Jaros

06/19/2022, 6:04 PM
yes
j

Javier

06/19/2022, 6:04 PM
apply ksp in the plugins block in your precompiled plugin instead of with the manager
r

Robert Jaros

06/20/2022, 9:35 AM
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

Javier

06/20/2022, 9:35 AM
I would apply the plugins in the plugins block in precompiled plugins instead of with apply
r

Robert Jaros

06/20/2022, 9:36 AM
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

Javier

06/20/2022, 9:39 AM
that is weird
is your project open source?
r

Robert Jaros

06/20/2022, 9:43 AM
Yes. But it's quite large and complicated (KVision).
j

Javier

06/20/2022, 9:44 AM
is there a branch where you are trying these things?
r

Robert Jaros

06/20/2022, 9:45 AM
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

Javier

06/20/2022, 10:03 AM
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

Robert Jaros

06/20/2022, 10:10 AM
Yep, I have a normal plugin not a precompiled one. Sorry for misleading. I'v just googled what a precompiled gradle plugin is 😉
👍 1
10 Views