Skip to content

Commit 60149ea

Browse files
committed
GH-660 - Dependency checks now explicitly skip module-internal dependencies.
As we process a type's entire type hierarchy for dependencies we might discover a foreign module's internal dependencies for modules that declare allowed dependencies explicitly. Explicitly declared dependencies so far solely verified the target being explicitly listed, which, for internal dependencies does not make sense. We now immediately start checking the source and target modules to be equivalent, in which case we can skip any further processing.
1 parent 3d32b20 commit 60149ea

File tree

8 files changed

+107
-2
lines changed

8 files changed

+107
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,13 @@ Violations isValidDependencyWithin(ApplicationModules modules) {
10071007

10081008
var originModule = getExistingModuleOf(source, modules);
10091009
var targetModule = getExistingModuleOf(target, modules);
1010+
var violations = Violations.NONE;
1011+
1012+
if (originModule.equals(targetModule)) {
1013+
return violations;
1014+
}
10101015

10111016
var declaredDependencies = originModule.getDeclaredDependencies(modules);
1012-
var violations = Violations.NONE;
10131017

10141018
// Check explicitly defined allowed targets
10151019
if (!declaredDependencies.isAllowedDependency(target)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @author Oliver Drotbohm
3737
*/
38-
class TestUtils {
38+
public class TestUtils {
3939

4040
private static Supplier<JavaClasses> imported = SingletonSupplier.of(() -> new ClassFileImporter() //
4141
.importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 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 reproducers.gh660.first;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.springframework.modulith.core.TestUtils;
20+
21+
/**
22+
* @author Oliver Drotbohm
23+
*/
24+
class Gh660Tests {
25+
26+
@Test // GH-660
27+
void doesNotRejectInternalDependencies() {
28+
TestUtils.of("reproducers.gh660").verify();
29+
}
30+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@org.springframework.modulith.ApplicationModule(allowedDependencies = {})
2+
package reproducers.gh660.first;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2024 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 reproducers.gh660.first.repository;
17+
18+
/**
19+
* @author Oliver Drotbohm
20+
*/
21+
public class Product {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2024 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 reproducers.gh660.first.repository;
17+
18+
/**
19+
* @author Oliver Drotbohm
20+
*/
21+
public interface ProductRepository {
22+
Product save(Product product);
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@org.springframework.modulith.NamedInterface
2+
package reproducers.gh660.first.repository;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2024 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 reproducers.gh660.second;
17+
18+
import reproducers.gh660.first.repository.ProductRepository;
19+
20+
/**
21+
* @author Oliver Drotbohm
22+
*/
23+
public interface ExtendingRepository extends ProductRepository {}

0 commit comments

Comments
 (0)