That is, run groovy scrips in dev image without prior compilation,
overcoming the issue that Micronaut's dependency injection relies on
statically compiled class files with seems incompatible with groovy
scripting/interpretation (without prior compilation).
The Micronaut Classloader relies on compiled classes being loaded by
java classloader.
ApplicationContext.run()
..
SoftServiceLocader.collectDynamicServices()
Class.forName()
This uses the Java classloader which does not know the Groovy-only
classes when interpreting (scripting) without prior compilation.
This can be overcome by keeping the $xyz classes created by Micronaut's
annotation processor inside the dev image and setting the Groovy
classloader like so:
ApplicationContext.run(Thread.currentThread().contextClassLoader).
However, with TRACE logs enabled for "io.micronaut.context" we can
then see stacktraces like this in the log.
NoClassDefFoundError: com/cloudogu/gitops/jenkins/GlobalPropertyManager
at com.cloudogu.gitops.jenkins.$GlobalPropertyManager$Definition$Reference.getBeanType(Unknown Source)
Eventually we fail with
No bean of type [com.cloudogu.gitops.config.ApplicationConfigurator] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
at io.micronaut.context.DefaultBeanContext.newNoSuchBeanException(DefaultBeanContext.java:2773)
at io.micronaut.context.DefaultApplicationContext.newNoSuchBeanException(DefaultApplicationContext.java:292)
at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2735)
So we choose the pragmatic workaround of instantiating all classes
manually when running the dev image.
Harder to maintain, but at least a working solution.