Skip to content

Commit c82e0ff

Browse files
committed
GH-668 - 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 d763ee0 commit c82e0ff

File tree

8 files changed

+115
-3
lines changed

8 files changed

+115
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,13 @@ Violations isValidDependencyWithin(ApplicationModules modules) {
968968

969969
var originModule = getExistingModuleOf(source, modules);
970970
var targetModule = getExistingModuleOf(target, modules);
971+
var violations = Violations.NONE;
971972

972-
DeclaredDependencies declaredDependencies = originModule.getDeclaredDependencies(modules);
973-
Violations violations = Violations.NONE;
973+
if (originModule.equals(targetModule)) {
974+
return violations;
975+
}
976+
977+
var declaredDependencies = originModule.getDeclaredDependencies(modules);
974978

975979
// Check explicitly defined allowed targets
976980
if (!declaredDependencies.isAllowedDependency(target)) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
1919

20+
import java.util.List;
2021
import java.util.function.Supplier;
2122

2223
import org.jmolecules.ddd.annotation.AggregateRoot;
@@ -28,13 +29,14 @@
2829
import com.tngtech.archunit.core.domain.JavaClass;
2930
import com.tngtech.archunit.core.domain.JavaClasses;
3031
import com.tngtech.archunit.core.importer.ClassFileImporter;
32+
import com.tngtech.archunit.core.importer.ImportOption;
3133

3234
/**
3335
* Utilities for testing.
3436
*
3537
* @author Oliver Drotbohm
3638
*/
37-
class TestUtils {
39+
public class TestUtils {
3840

3941
private static Supplier<JavaClasses> imported = SingletonSupplier.of(() -> new ClassFileImporter() //
4042
.importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class));
@@ -92,4 +94,9 @@ private static Classes getClasses(String packageName) {
9294
return Classes.of(new ClassFileImporter()
9395
.importPackages(packageName));
9496
}
97+
98+
public static ApplicationModules of(String basePackage, String... ignoredPackages) {
99+
return new ApplicationModules(ModulithMetadata.of(basePackage), List.of(basePackage),
100+
JavaClass.Predicates.resideInAnyPackage(ignoredPackages), false, new ImportOption.OnlyIncludeTests());
101+
}
95102
}
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)