https://kotlinlang.org logo
#gradle
Title
# gradle
m

melix

11/07/2023, 5:31 PM
Hi folks. I'm having an issue upgrading the Micronaut Gradle plugins to Kotlin 1.9.20. I have a couple tests failing when using kapt+a custom source set. It seems that the annotation processors are not called anymore in 1.9.20 on these custom source sets. Does that ring a bell to anyone?
t

tapchicoma

11/07/2023, 9:32 PM
Please open a Kotlin issue with a repro. Hard to say what could be wrong here
m

melix

11/08/2023, 9:02 AM
I cannot easily build a repro, this is a quite involved plugin. Or I could point you at a breaking PR if it helps.
t

tapchicoma

11/08/2023, 9:04 AM
afaik there were no significant changes on the Kapt/Gradle side between 1.9.10 and 1.9.20 releases. In 1.9.0 release kapt tasks were decoupled from related
KotlinJvmCompile
tasks meaning if you are doing some additional configuration on
KotlinJvmCompile
task - you either also need to repeat it for
KaptGenerateStubs
task or use more generic approach
m

melix

11/08/2023, 9:04 AM
I tested with 1.9.0, 1.9.10 and 1.9.20, it starts breaking with 1.9.20
🤔 1
when using
kapt.verbose=true
I'm supposed to see debug info for all kapt tasks, right? Currently I see it only for
kaptKotlin
, but not for the
kaptCustomKotlin
task
t

tapchicoma

11/08/2023, 9:07 AM
hmm, yes - for all
Kapt
tasks
that is strange. Is Micronaut Gradle plugin closed sourced?
m

melix

11/08/2023, 9:09 AM
no it's OSS
t

tapchicoma

11/08/2023, 9:10 AM
I will try to look into it tomorrow
👍 1
m

melix

11/08/2023, 9:10 AM
you can run
:functional-tests:test --tests "io.micronaut.gradle.kotlin.KotlinLibraryFunctionalTest.test custom sourceSet for micronaut-library and kotlin with kotlin DSL for #plugin"
and see it fail
👍 1
by changing the Kotlin version in
libs.versions.toml
to 1.9.10 it passes
I'll investigate more but I lack knowledge of how the Kotlin plugins set things up
Back to debugging. I'm reaching this:
No annotation processors provided. Skip KAPT processing.
So now have to figure out why...
t

tapchicoma

11/08/2023, 4:04 PM
aha, one sec - will find related commit
m

melix

11/08/2023, 4:06 PM
This is fishy. After I added this configuration block, I'm getting further:
Copy code
configurations.all {
               if (name.contains("kapt") && name.contains("Classpath") && name.contains("Custom")) {
                  println(name)
                  incoming.beforeResolve {
                      extendsFrom(configurations["kaptCustom"])
                  }
               }
            }
but still failing...
t

tapchicoma

11/08/2023, 4:07 PM
Please check this commit
though it is somewhat opposite to empty AP
m

melix

11/08/2023, 4:56 PM
Yeah, seems to be the opposite of what I'm seeing 🤔
oh wait seems this commit is not in 1.9.20
🤔 1
t

tapchicoma

11/09/2023, 8:57 AM
right 🤦‍♂️ It should be only in 2.0.0-Beta1
m

melix

11/09/2023, 8:58 AM
but then it means that may be the problem I'm seeing
let me see if I manually add dependencies from parent configurations before resolving...
t

tapchicoma

11/09/2023, 8:58 AM
though the issue it tries to fix is quite old one 🤔
m

melix

11/09/2023, 9:03 AM
Copy code
configurations.all {
               var conf = this
               if (name == "kaptClasspath_kaptCustomKotlin") {
                  incoming.beforeResolve {
                      configurations["kaptCustom"].dependencies.forEach {
                        conf.dependencies.add(it)
                      }
                  }
               }
            }
gets me further but still nothing. And it looks like there are no stubs generated 😮‍💨
t

tapchicoma

11/09/2023, 12:50 PM
The more I look into it - the more it looks like kapt compiler plugin issue itself and not related to Gradle/Kapt. And there was some significant refactoring to support K2. Please open a new issue - you could just reference your branch as a repro.
m

melix

11/09/2023, 12:52 PM
mmm that would be strange since it works perfectly fine for the main source set
t

tapchicoma

11/09/2023, 12:54 PM
ah, my bad - my comment above is incorrect. Was looking into wrong place.
m

melix

11/09/2023, 12:55 PM
I suspect it's related to stubs not being generated in this case
t

tapchicoma

11/09/2023, 12:55 PM
I see that your plugin tries to configure Kapt standard configurations like "kapt", "kaptTest", but not for custom source set - "kaptCustom". Is it intended behaviour?
m

melix

11/09/2023, 12:56 PM
it does configure it too
t

tapchicoma

11/09/2023, 12:57 PM
Basically kapt task exists on this condition. For main source set
kaptClasspath
is not empty, but for custom one - it is empty
m

melix

11/09/2023, 12:57 PM
I see my code being called for
kaptCustom
🤔 1
so yes, something has changed around this. That's why I had to add the dirty trick to reintroduce the
extendsFrom
but even when I do so, it doesn't work and doesn't generate stubs
t

tapchicoma

11/09/2023, 12:59 PM
extendsFrom
is ignored for kapt configurations in 1.9.20
the fix I've posted above fixes it
m

melix

11/09/2023, 12:59 PM
mmm, how is one supposed to add dependencies then?
The code I added in the test:
Copy code
configurations.all {
               var conf = this
               if (name == "kaptClasspath_kaptCustomKotlin") {
                  incoming.beforeResolve {
                      configurations["kaptCustom"].dependencies.forEach {
                        conf.dependencies.add(it)
                      }
                  }
               }
            }
works around the fact that
extendsFrom
is ignored (uh, silly). Yet, now I see the kapt task being invoked, but it doesn't work since it says all sources are up-to-date, which I think comes from the fact no stubs are generated.
So I'm wondering if I need a similar trick for stubs generation
this is basically a blocker for Micronaut 4.2 release, which supports Java 21
so if I can workaround, even with a temporary hack, that's better than nothing
yeah I think it's the same issue, when the task is invoked the kapt classpath is empty
now have to figure out what configuration it's using
So this is
kaptClasspath
for the
kaptGenerateStubsCustomKotlin
task
if you compare it with the "default" kapt generate stubs task
for some reason the custom one seems unconfigured
t

tapchicoma

11/09/2023, 1:49 PM
is it possible to run the test with Gradle 8.1?
m

melix

11/09/2023, 1:51 PM
trying...
also fails
t

tapchicoma

11/09/2023, 1:53 PM
From what I see on this line for
kaptCustom
configuration kapt subplugin does not see any declared dependencies
m

melix

11/09/2023, 1:54 PM
the dependencies are added in an
afterEvaluate
(see link above). However from what I've seen, they are still added before this code is executed.
t

tapchicoma

11/09/2023, 1:55 PM
aha - and it is being called after script evaluation and before `afterEvaluate`s
m

melix

11/09/2023, 1:55 PM
doesn't explain why the stubs task isn't configured with a configuration tho
t

tapchicoma

11/09/2023, 1:55 PM
so this is the cause
it could affect stub as well
is it possible to add dependency without using
afterEvaluate
?
m

melix

11/09/2023, 1:56 PM
no, because it's an extension which is configured by the user, so we can't tell what's going to be added
basically we're looking at the source sets that the user has declares as "additional source sets to process"
t

tapchicoma

11/09/2023, 1:59 PM
I could not come up with any workaround except dropping usage of
afterEvaluate
kodee sad And I advice you to create an issue - possibly we could fix it in 1.9.21 release
m

melix

11/09/2023, 2:03 PM
I will see if I can configure eagerly instead, it's a breaking change, but might be acceptable...
t

tapchicoma

11/15/2023, 4:13 PM
Hi, the fix should be available in the 1.9.21 release - now kapt task should receive dependencies added in
afterEvaluate
👍 1
4 Views