GH-601 - Support for wildcard references to named interfaces in explicitly defined allowed application module dependencies.

When defining allowed application module dependencies to named interfaces, the asterisk can now be used to allow referencing all named interfaces declared by the target module.
This commit is contained in:
Oliver Drotbohm
2024-05-16 11:08:45 +02:00
parent e9203ca159
commit 51c5f0bf42
6 changed files with 115 additions and 24 deletions

View File

@@ -293,6 +293,7 @@ The effect of that declaration is twofold: first, code in other application modu
Application modules are able to refer to the named interface in explicit dependency declarations.
Assume the __inventory__ module was making use of that, it could refer to the above declared named interface like this:
.Defining allowed dependencies to dedicated named interfaces
[tabs]
======
Java::
@@ -300,7 +301,7 @@ Java::
[source, java, role="primary", chomp="none"]
----
@org.springframework.modulith.ApplicationModule(
allowedDependencies = "order::spi"
allowedDependencies = "order :: spi"
)
package example.inventory;
----
@@ -309,7 +310,7 @@ Kotlin::
[source, kotlin, role="secondary", chomp="none"]
----
@org.springframework.modulith.ApplicationModule(
allowedDependencies = "order::spi"
allowedDependencies = "order :: spi"
)
package example.inventory
----
@@ -319,6 +320,31 @@ Note how we concatenate the named interface's name `spi` via the double colon `:
In this setup, code in __inventory__ would be allowed to depend on `SomeSpiInterface` and other code residing in the `order.spi` interface, but not on `OrderManagement` for example.
For modules without explicitly described dependencies, both the application module root package *and* the SPI one are accessible.
If you wanted to express that an application module is allowed to refer to all explicitly declared named interfaces, you can use the asterisk (``*``) as follows:
.Using the asterisk to declare allowed dependencies to all declared named interfaces
[tabs]
======
Java::
+
[source, java, role="primary", chomp="none"]
----
@org.springframework.modulith.ApplicationModule(
allowedDependencies = "order :: *"
)
package example.inventory;
----
Kotlin::
+
[source, kotlin, role="secondary", chomp="none"]
----
@org.springframework.modulith.ApplicationModule(
allowedDependencies = "order :: *"
)
package example.inventory
----
======
[[customizing-modules]]
=== Customizing Module Detection