Micronaut-core: BeanDefinitionReference not generated with kapt incremental annotations processing when class interface is changed

Created on 16 Jul 2020  路  12Comments  路  Source: micronaut-projects/micronaut-core

In 2.0.0.

I'm continuing to chase hotswap problems with kapt, after #3734.

Now, I'm stuck on random NoSuchBeanException after I change the class interface. In such a scenario the hotswap fails (and it should). But after restarting the server I frequently stumble upon NoSuchBeanException.

It seems, when the class interface changes, and kapt works in incremental annotations processing mode, the annotations aren't processes and generated BeanDefinitionReference is empty. I have the following micronaut application:

public class Application {

    public static void main(String[] args) {
        Micronaut.run(Application.class);
    }

}

@Singleton @Validated
public class AutoStartingBean {

    public static final Logger logger = LoggerFactory.getLogger(AutoStartingBean.class);

    @EventListener
    public void start(StartupEvent event) {
        logger.debug("Starting...");
    }

}

And generated BeanDefinitionReference is:

micronaut.general.$AutoStartingBean$ApplicationEventListener$start1$InterceptedDefinitionClass
micronaut.general.$$AutoStartingBeanDefinition$InterceptedDefinitionClass
micronaut.general.$AutoStartingBeanDefinitionClass

When I add some method to Application and rebuild with gradle build, the BeanDefinitionReference is missing (in the other project it sometimes is present and contains fewer beans than it should). The curious thing is that when I add a method to AutoStartingBean, the BeanDefinitionReference file is generated properly again. Otherwise, only gradle clean helps.

It seems, because when I change Application kapt incremental processing skips processing of AutoStartingBean, it is never re-generated by kapt and never gets to BeanDefinitionReference. While all previously generated classes are still in the right spot:

$ ls build/tmp/kapt3/classes/main/micronaut/general/
AutoStartingBean$ApplicationEventListener$start1$Intercepted.class
$AutoStartingBean$ApplicationEventListener$start1$InterceptedDefinition.class
$AutoStartingBean$ApplicationEventListener$start1$InterceptedDefinitionClass.class
AutoStartingBean$ApplicationEventListener$start1$Intercepted$$proxy0.class
$AutoStartingBeanDefinition.class
$AutoStartingBeanDefinitionClass.class
$AutoStartingBeanDefinition$Intercepted.class
$$AutoStartingBeanDefinition$InterceptedDefinition.class
$$AutoStartingBeanDefinition$InterceptedDefinitionClass.class
$$AutoStartingBeanDefinition$InterceptedDefinition$$exec1.class
$AutoStartingBeanDefinition$Intercepted$$proxy0.class

So, the problem is only related to BeanDefinitionReference file generator.

I've recorded this problem here. Also, I provide test repository for this problem here.

awaiting third-party

All 12 comments

Might be related to https://github.com/gradle/gradle/issues/13767 although that is Java and in Java's case it fails fast with an error but looks like Kotlin maybe silently swallows the problem

Since this problem doesn't exist in the Java impl it must be an issue with KAPT. Could you report an issue to https://youtrack.jetbrains.com/issues/KT and link it here. Thanks.

@graemerocher Unfortunately, they moved the ticket to the backlog without solving it. It currently means that kotlin+linux is generally a bad idea, especially if you use any annotation processing libs. And what is really sad for me it now means that Micronaut+kotlin+linux is generally a bad idea...

Maybe you could push them a bit to debug it?

During investigation of original issue I've found another one with Gradle Java project (look like regression in Gradle): https://github.com/gradle/gradle/issues/15097

@max-kammerer thanks for the report and I am glad to hear you are investigating this issue :)

Hi Folks! Fix for this problem is available since 1.4.30-dev-3102 Kotlin compiler build. We would appreciate for any early feedback for this changes.
Compiler plugin could be obtained from https://oss.sonatype.org/content/repositories/snapshots/ repository

@max-kammerer Thanks that is great news! @l0co could you try out the fix and provide feedback?

I'm putting the feedback to kotlin ticket.

It seems it's fixed. I've upgraded the test repo with this commit where you can check it works. However, I'd wait with resolving this ticket to official release. In the meantime I'm going to work a bit with this version in IDE and I'll give a feedback if there's something wrong.

@l0co that is great news! @max-kammerer thanks and I am glad KAPT is getting some attention :)

Kotlin 1.4.30 is out with KT-40493 included. So far I didn't experience the kapt issue from the past, fingers crossed :)

Was this page helpful?
0 / 5 - 0 ratings