spring-projects / spring-modulith

Modular applications with Spring Boot
https://spring.io/projects/spring-modulith
Apache License 2.0
779 stars 129 forks source link

`ApplicationModules.of(…)` throws `NoClassDefFoundError` when using the jMolecules Kotlin library #801

Closed breun closed 2 weeks ago

breun commented 3 weeks ago

I'm trying out Spring Modulith 1.2.3 with a Spring Boot 3.3.3 project that is written in Kotlin. On the Verifying Application Module Structure page I read about jMolecules, and I found that jmolecules-ddd has a Kotlin counterpart called kmolecules-ddd.

However, after adding org.jmolecules:kmolecules-ddd to my project, I got java.lang.NoClassDefFoundError: org/jmolecules/ddd/annotation/Module when calling org.springframework.modulith.core.ApplicationModuleInformation#of for Spring Modulith application module verification and documentation generation.

This seems to happen because JMoleculesTypes.isPresent() returns true, because org.jmolecules.ddd.annotation.Entity is present (provided by kmolecules-ddd), but JMoleculesModule.supports(lookup) then tries to look up org.jmolecules.ddd.annotation.Module, which is not provided by kmolecules-ddd (although it is indeed provided by jmolecules-ddd).

breun commented 3 weeks ago

@BoundedContext and @Module were added to jmolecules-ddd via https://github.com/xmolecules/jmolecules/issues/20, but weren't added to kmolecules-ddd. I've created https://github.com/xmolecules/jmolecules/issues/126 for this.

breun commented 3 weeks ago

I'm now thinking that these annotations are probably missing from kmolecules-ddd, because these are package-level annotations and Kotlin doesn't provide a way to define package-level annotations.

Maybe it's then best to let Spring Modulith not fail when org.jmolecules.ddd.annotation.Module is not present?

odrotbohm commented 2 weeks ago

An improve guard should be in place. Feel free to give the snapshots a try!