diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java index 60bd60d1..50bcb1e1 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java @@ -968,9 +968,13 @@ public class ApplicationModule { var originModule = getExistingModuleOf(source, modules); var targetModule = getExistingModuleOf(target, modules); + var violations = Violations.NONE; - DeclaredDependencies declaredDependencies = originModule.getDeclaredDependencies(modules); - Violations violations = Violations.NONE; + if (originModule.equals(targetModule)) { + return violations; + } + + var declaredDependencies = originModule.getDeclaredDependencies(modules); // Check explicitly defined allowed targets if (!declaredDependencies.isAllowedDependency(target)) { diff --git a/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java b/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java index 623557a5..c4414db2 100644 --- a/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java +++ b/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java @@ -17,6 +17,7 @@ package org.springframework.modulith.core; import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*; +import java.util.List; import java.util.function.Supplier; import org.jmolecules.ddd.annotation.AggregateRoot; @@ -28,13 +29,14 @@ import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.importer.ClassFileImporter; +import com.tngtech.archunit.core.importer.ImportOption; /** * Utilities for testing. * * @author Oliver Drotbohm */ -class TestUtils { +public class TestUtils { private static Supplier imported = SingletonSupplier.of(() -> new ClassFileImporter() // .importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class)); @@ -92,4 +94,9 @@ class TestUtils { return Classes.of(new ClassFileImporter() .importPackages(packageName)); } + + public static ApplicationModules of(String basePackage, String... ignoredPackages) { + return new ApplicationModules(ModulithMetadata.of(basePackage), List.of(basePackage), + JavaClass.Predicates.resideInAnyPackage(ignoredPackages), false, new ImportOption.OnlyIncludeTests()); + } } diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/first/Gh660Tests.java b/spring-modulith-core/src/test/java/reproducers/gh660/first/Gh660Tests.java new file mode 100644 index 00000000..d3fb4cac --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/first/Gh660Tests.java @@ -0,0 +1,30 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reproducers.gh660.first; + +import org.junit.jupiter.api.Test; +import org.springframework.modulith.core.TestUtils; + +/** + * @author Oliver Drotbohm + */ +class Gh660Tests { + + @Test // GH-660 + void doesNotRejectInternalDependencies() { + TestUtils.of("reproducers.gh660").verify(); + } +} diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/first/package-info.java b/spring-modulith-core/src/test/java/reproducers/gh660/first/package-info.java new file mode 100644 index 00000000..5a63dd3a --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/first/package-info.java @@ -0,0 +1,2 @@ +@org.springframework.modulith.ApplicationModule(allowedDependencies = {}) +package reproducers.gh660.first; diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/Product.java b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/Product.java new file mode 100644 index 00000000..0c18dfd6 --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/Product.java @@ -0,0 +1,21 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reproducers.gh660.first.repository; + +/** + * @author Oliver Drotbohm + */ +public class Product {} diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/ProductRepository.java b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/ProductRepository.java new file mode 100644 index 00000000..50b74f5d --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/ProductRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reproducers.gh660.first.repository; + +/** + * @author Oliver Drotbohm + */ +public interface ProductRepository { + Product save(Product product); +} diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/package-info.java b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/package-info.java new file mode 100644 index 00000000..65180dd6 --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/first/repository/package-info.java @@ -0,0 +1,2 @@ +@org.springframework.modulith.NamedInterface +package reproducers.gh660.first.repository; diff --git a/spring-modulith-core/src/test/java/reproducers/gh660/second/ExtendingRepository.java b/spring-modulith-core/src/test/java/reproducers/gh660/second/ExtendingRepository.java new file mode 100644 index 00000000..1f2c4ded --- /dev/null +++ b/spring-modulith-core/src/test/java/reproducers/gh660/second/ExtendingRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reproducers.gh660.second; + +import reproducers.gh660.first.repository.ProductRepository; + +/** + * @author Oliver Drotbohm + */ +public interface ExtendingRepository extends ProductRepository {}