diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java index 83d1c5fb..c6f8e4ba 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java @@ -177,7 +177,7 @@ public class ApplicationModule { Assert.notNull(modules, "Modules must not be null!"); Assert.notNull(depth, "Dependency depth must not be null!"); - return streamDependencies(modules, depth); + return streamBootstrapDependencies(modules, depth); } /** @@ -187,12 +187,12 @@ public class ApplicationModule { * @param depth must not be {@literal null}. * @return */ - public Stream getBasePackages(ApplicationModules modules, DependencyDepth depth) { + public Stream getBootstrapBasePackages(ApplicationModules modules, DependencyDepth depth) { Assert.notNull(modules, "Modules must not be null!"); Assert.notNull(depth, "Dependency depth must not be null!"); - Stream dependencies = streamDependencies(modules, depth); + Stream dependencies = streamBootstrapDependencies(modules, depth); return Stream.concat(Stream.of(this), dependencies) // .map(ApplicationModule::getBasePackage); @@ -380,27 +380,28 @@ public class ApplicationModule { .flatMap(it -> getModuleDependenciesOf(it, modules)); } - private Stream streamDependencies(ApplicationModules modules, DependencyDepth depth) { + private Stream streamBootstrapDependencies(ApplicationModules modules, DependencyDepth depth) { switch (depth) { case NONE: return Stream.empty(); case IMMEDIATE: - return getDirectModuleDependencies(modules); + return getDirectModuleBootstrapDependencies(modules); case ALL: default: - return getDirectModuleDependencies(modules) // - .flatMap(it -> Stream.concat(Stream.of(it), it.streamDependencies(modules, DependencyDepth.ALL))) // + return getDirectModuleBootstrapDependencies(modules) // + .flatMap(it -> Stream.concat(Stream.of(it), it.streamBootstrapDependencies(modules, DependencyDepth.ALL))) // .distinct(); } } - private Stream getDirectModuleDependencies(ApplicationModules modules) { + private Stream getDirectModuleBootstrapDependencies(ApplicationModules modules) { return getSpringBeansInternal().stream() // .flatMap(it -> ModuleDependency.fromType(it)) // .filter(it -> isDependencyToOtherModule(it.target, modules)) // + .filter(it -> it.hasType(DependencyType.USES_COMPONENT)) // .map(it -> modules.getModuleByType(it.target)) // .distinct() // .flatMap(it -> it.map(Stream::of).orElseGet(Stream::empty)); diff --git a/spring-modulith-integration-test/src/main/java/com/acme/myproject/moduleD/EventListenerD.java b/spring-modulith-integration-test/src/main/java/com/acme/myproject/moduleD/EventListenerD.java new file mode 100644 index 00000000..fb6ef460 --- /dev/null +++ b/spring-modulith-integration-test/src/main/java/com/acme/myproject/moduleD/EventListenerD.java @@ -0,0 +1,31 @@ +/* + * Copyright 2022 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 com.acme.myproject.moduleD; + +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import com.acme.myproject.moduleA.SomeEventA; + +/** + * @author Oliver Drotbohm + */ +@Component +class EventListenerD { + + @EventListener + void on(SomeEventA event) {} +} diff --git a/spring-modulith-integration-test/src/test/java/com/acme/myproject/ModulithTest.java b/spring-modulith-integration-test/src/test/java/com/acme/myproject/ModulithTest.java index 7646aa97..6326123f 100644 --- a/spring-modulith-integration-test/src/test/java/com/acme/myproject/ModulithTest.java +++ b/spring-modulith-integration-test/src/test/java/com/acme/myproject/ModulithTest.java @@ -18,6 +18,7 @@ package com.acme.myproject; import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.Test; +import org.springframework.modulith.model.ApplicationModule; import org.springframework.modulith.model.ApplicationModules; import org.springframework.modulith.model.ApplicationModules.Filters; import org.springframework.modulith.model.Violations; @@ -71,4 +72,16 @@ class ModulithTest { .withMessageContaining("CycleA") // .withMessageContaining("CycleB"); } + + @Test // GH-46 + void doesNotIncludeEventListenerDependencyInBootstrapOnes() { + + var modules = ApplicationModules.of(Application.class, DEFAULT_EXCLUSIONS); + + assertThat(modules.getModuleByName("moduleD")).hasValueSatisfying(it -> { + assertThat(it.getBootstrapDependencies(modules)) + .map(ApplicationModule::getName) + .doesNotContain("moduleA"); + }); + } } diff --git a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java index b1f1ecc9..eda1527f 100644 --- a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java +++ b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java @@ -72,7 +72,7 @@ public class ModuleTestExecution implements Iterable { this.basePackages = Suppliers.memoize(() -> { - Stream moduleBasePackages = module.getBasePackages(modules, bootstrapMode.getDepth()); + Stream moduleBasePackages = module.getBootstrapBasePackages(modules, bootstrapMode.getDepth()); Stream sharedBasePackages = modules.getSharedModules().stream().map(it -> it.getBasePackage()); Stream extraPackages = extraIncludes.stream().map(ApplicationModule::getBasePackage);