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

No architectural violation reported when referring to constants in another module #831

Closed SuryaEnjarapu closed 2 days ago

SuryaEnjarapu commented 1 week ago

Able to use constants from another module thats present submodule/package. while executing verify() its does throwing any violations, is it right behavior?

odrotbohm commented 1 week ago

Can you provide a minimal sample? Not that the JVM usually inlines references to static final fields of primitives and Strings (see this ticket in ArchUnit), so that — technically, when inspecting the byte code — the referring class does not have a dependency on the target one.

SuryaEnjarapu commented 3 days ago

"Hi, I'm still encountering this issue in a company project (which I cannot share). However, I tested the same scenario using an example from SivaLabs with Spring Modulith, and it worked as expected. The main differences are that I'm using Java 17 with Spring Modulith 1.2.2, while the SivaLabs example uses Java 21 with Spring Modulith 1.3. I don't believe these differences are causing the issue; it might be related to environment or dependency issues. @sivaprasadreddy Please refer to the screenshot of my scenario, where it’s working as expected."

In this below example, I a directly trying use the InventoryConstants in common module image

odrotbohm commented 2 days ago

As described above, this is a side effect of the JVM inlining the constants. In other words, the compiled code does not contain that reference. Things might look different if you rather expose the constant as a method, though.

SuryaEnjarapu commented 2 days ago

Ok Thank you for the response, will try to figure out and update here if i found solution or root cause. Thank you!!