Skip to content

Commit 5d41072

Browse files
committed
GH-1143 - Detect @NamedInterface on composed annotations.
1 parent c9ad2b8 commit 5d41072

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-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(JavaPackage basePackage) {
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/NamedInterfacesUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ void detectsNamedInterfacesATypeIsContainedIn() {
9090
.containsExactlyInAnyOrder("spi", "kpi");
9191
}
9292

93+
@Test // GH-1139
94+
void discoveredNamedInterfaceOnComposedAnnotation() {
95+
96+
var pkg = TestUtils.getPackage(example.metani.Exposed.class);
97+
98+
var result = NamedInterfaces.discoverNamedInterfaces(pkg);
99+
100+
assertThat(result).hasSize(2)
101+
.extracting(NamedInterface::getName)
102+
.containsExactlyInAnyOrder(NamedInterface.UNNAMED_NAME, "api");
103+
}
104+
93105
private static void assertInterfaceContains(NamedInterfaces interfaces, String name, Class<?>... types) {
94106

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

0 commit comments

Comments
 (0)