-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kapt incremental processing not working #4882
Comments
I'm not able to reproduce this following the steps in the video using Micronaut 2.3.1. Note that the comment you quoted
That was an experiment and that change never went into Micronaut, the bugs mostly existed in Gradle and Kotlin. Make sure when you are upgrading you also upgrade to the latest versions of Gradle and Kotlin both of which had numerous annotation processing related bugs that could be impacting your experience. |
@theHacker can you try Kotlin 1.4.30 with Gradle 6.8 and feedback if you still see issues? |
Thanks for answering so quickly. I tried also quickly with your Demo project (this uses Kotlin 1.4.10). Changing the Kotlin version leads to this error message
I created a shell script, with which you can easily reproduce the issue: #!/bin/zsh
# Download
echo "Download Micronaut demo project"
echo "--------------------------------"
echo ""
curl "https://launch.micronaut.io/demo.zip?lang=kotlin" -o demo.zip
unzip demo.zip -d demo
rm demo.zip
cd demo
# Output versions
echo ""
echo ""
echo "Outputting versions of Kotlin and Gradle:"
echo " EXPECTED:"
echo " Kotlin 1.4.10 + Gradle 6.8"
echo " ACTUAL:"
cat gradle.properties | grep kotlin
cat gradle/wrapper/gradle-wrapper.properties | grep Url
echo ""
echo ""
# Build once
echo "Building once"
echo "---------------"
./gradlew kaptTestKotlin
echo ""
echo "After initial build"
echo "--------------------"
echo ""
echo "Test services file META-INF/services/io.micronaut.inject.BeanDefinitionReference:"
echo " EXPECTED: all beans = 1 bean: \$DemoTestDefinitionClass"
echo " ACTUAL:"
cat build/tmp/kapt3/classes/test/META-INF/services/io.micronaut.inject.BeanDefinitionReference
echo ""
# Add a bean
echo "We now add a bean and build again"
echo "----------------------------------"
echo "@io.micronaut.context.annotation.Factory class AnyBean" >> src/test/kotlin/demo/DemoTest.kt
./gradlew kaptTestKotlin
echo ""
echo "Now see the bug"
echo "----------------"
echo ""
echo "Test services file META-INF/services/io.micronaut.inject.BeanDefinitionReference:"
echo " EXPECTED: all beans = 2 beans: \$DemoTestDefinitionClass and new \$AnyBeanDefinitionClass"
echo " ACTUAL:"
cat build/tmp/kapt3/classes/test/META-INF/services/io.micronaut.inject.BeanDefinitionReference
echo ""
echo ""
echo "The actual output however does not contain \$DemoTestDefinitionClass anymore!!!"
echo "" |
I was able to reproduce the issue with Micronaut 2.3.2 and Kotlin 1.4.30 |
What is interesting is that I can reproduce it with |
Adding |
I created this issue for you https://youtrack.jetbrains.com/issue/KT-44989 |
@theHacker The kotlinVersion needs changed to 1.4.30 and the build plugin versions need changed as well. In that case it works correctly. |
Task List
Steps to Reproduce
curl https://launch.micronaut.io/demo.zip?lang=kotlin -o demo.zip && unzip demo.zip -d demo
./gradlew test
.Screencast: https://owncloud.senacor.com/index.php/s/cQr6wlFtArBsrGK
Expected Behaviour
The test will run. (Because the test bean is in the
ApplicationContext
)Actual Behaviour
The test will not run. (The test bean is missing in the
ApplicationContext
)Environment Information
Problem
We have multiple projects running with Micronaut. Right now we are in the process of updating them from Micronaut 1.3.7 to Micronaut 2.x.
We have working solutions with Micronaut 2.2.1 (verified myself) and 2.2.3 (no complains from the team).
However one project has heavy problems after the update to 2.2.1.
When changing test code, the annotation processor completely ignores every other bean, breaking everything.
To get everything working again
./gradlew clean
is necessary.Detailed analysis
DefaultBeanContext.start()
gets call.readAllBeanDefinitionClasses()
tries to read all bean definitions.resolveBeanDefinitionReferences()
uses theSoftServiceLoader
to load a list ofBeanDefinition
class names fromMETA-INF/services/io.micronaut.inject.BeanDefinitionReference
.This file gets generated when invoking
./gradlew kaptTestKotlin
.If a bean definition is missing at this point, it does not get loaded!
When changing a file, the annotation processor only writes the new/changed beans into the definition file.
Since this issue very strongly sounds like a problem with incremental annotation processing, I also tried disabling it.
However, for the issue, it does not matter, whether incremental annotation processing is enabled or not.
Impact / additional information
In our project, we have nearly 500 beans (test helper classes, configurations and the tests themselves) in the test scope.
In combination with the test framework (we use Kotest), we get misleading error messages:
JDBC related exceptions, because the test configuration class does not get executed and the
DataSource
will point to the wrong database.exceptions from Kotest unable to instantiate the test class, because there is no no-arg constructor.
I debugged into this case also.
MicronautKotestExtension.instantiate()
gets called, creates theApplicationContext
, but cannot find the test bean and then returnsnull
.This will generate a very misleading error message. The cause, that the test bean could not be found, is not printed out.
Maybe you want to add a fail-fast in https://github.com/micronaut-projects/micronaut-test/blob/v2.2.1/test-kotest/src/main/kotlin/io/micronaut/test/extensions/kotest/MicronautKotestExtension.kt#L96, when
createBean
is set, butcontext.bean
isnull
anyway?In the screencast you see the issue broken down to
gradlew
commands.In reality, we use IntelliJ and the Kotest IntelliJ plugin to launch the tests, while working.
./gradlew classes testClasses
when doing a build./gradlew test --tests "..."
when executing particular test methods/classes.Related issues
Beans are sometimes not injected in junit tests #4730
complains about bean injection failures. If the beans are not in the ApplicationContext, injection will fail.
All bean definitions are recreated during re-compilation #2922
This looks the issue leading to the problem. I researched the linked Micronaut and Gradle issues.
For me it verifies the time frame, where the issue was introduced (switching from Micronaut 1.3.7 to 2.x).
In 1.3.7 https://github.com/micronaut-projects/micronaut-core/blob/2.3.x/inject-java/src/main/java/io/micronaut/annotation/processing/ServiceDescriptionProcessor.java
did not exist yet.
I am not so deep into annotation processing and Gradle, to understand the discussion in this ticket about
aggregating vs isolating processor. The comment
leads me to think, you have broken something, leading to this bug in certain setups.
Right now, I don't know, where the error lies. Is it Micronaut, Gradle and/or specifics to project configuration?
Since I can reproduce with the Micronaut Demo also, I think, a bug report here isn't wrong :-)
Please feel free to ask, if you need additional information.
The text was updated successfully, but these errors were encountered: