Skip to content

Commit 4d1db81

Browse files
committed
GH-1142 - Detect @NamedInterface on composed annotations.
1 parent bf495be commit 4d1db81

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/NamedInterfaces.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private static List<NamedInterface> ofAnnotatedTypes(Classes classes) {
250250
.filter(it -> !JavaPackage.isPackageInfoType(it)) //
251251
.forEach(it -> {
252252

253-
if (!it.isAnnotatedWith(org.springframework.modulith.NamedInterface.class)) {
253+
if (!it.isMetaAnnotatedWith(org.springframework.modulith.NamedInterface.class)) {
254254
return;
255255
}
256256

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.metani;
17+
18+
/**
19+
* @author Oliver Drotbohm
20+
*/
21+
@ModuleApi
22+
public class Exposed {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example.metani;
17+
18+
import static java.lang.annotation.ElementType.*;
19+
import static java.lang.annotation.RetentionPolicy.*;
20+
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.Target;
23+
24+
import org.springframework.modulith.NamedInterface;
25+
26+
/**
27+
* @author Oliver Drotbohm
28+
*/
29+
@Retention(RUNTIME)
30+
@Target({ TYPE })
31+
@NamedInterface("api")
32+
public @interface ModuleApi {}

spring-modulith-core/src/test/java/org/springframework/modulith/core/ApplicationModulesUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void discoversComplexModuleArrangement() {
3737
.containsExactlyInAnyOrder(
3838
"invalid",
3939
"customId",
40+
"metani",
4041
"ni",
4142
"ni.nested",
4243
"ni.nested.b.first",

spring-modulith-core/src/test/java/org/springframework/modulith/core/NamedInterfacesUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ void detectsNamedInterfacesATypeIsContainedIn() {
9898
.containsExactlyInAnyOrder("spi", "kpi");
9999
}
100100

101+
@Test // GH-1139
102+
void discoveredNamedInterfaceOnComposedAnnotation() {
103+
104+
var pkg = TestUtils.getPackage(example.metani.Exposed.class);
105+
106+
var result = NamedInterfaces.discoverNamedInterfaces(pkg);
107+
108+
assertThat(result).hasSize(2)
109+
.extracting(NamedInterface::getName)
110+
.containsExactlyInAnyOrder(NamedInterface.UNNAMED_NAME, "api");
111+
}
112+
101113
private static void assertInterfaceContains(NamedInterfaces interfaces, String name, Class<?>... types) {
102114

103115
var classNames = Arrays.stream(types).map(Class::getName).toArray(String[]::new);

0 commit comments

Comments
 (0)