Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more sophisticated registration of modules by providing ApplicationModules.merge(ApplicationModules) #613

Open
9n opened this issue May 21, 2024 · 0 comments

Comments

@9n
Copy link

9n commented May 21, 2024

I want to use spring-modulith in a cross application (cross team) way, where modules may be shared by multiple applications (don't be confused with @Modulithic.sharedModules).
Providing following project:

my-app // my-app is maintained by team A
├─ pom.xml
├─ src/main/java
│  ├─ com.example.app
│  │  ├─ Application.java
│  │  ├─ moduleA/
│  │  ├─ moduleB/
├─ Maven Dependencies
│  ├─ shared-module-foo.jar  // shared modules maintained by other teams. e.g. team B
│  │  ├─ com.example.shared.foo
│  ├─ shared-module-bar.jar
│  │  ├─ com.example.shared.bar
│  ├─ spring-boot-starter-shared-modules.jar

Currently, shared modules foo and bar can be registered by annotating Application with @Modulithic(additionalPackages = { "com.example.shared" }) .
But I want shared modules get registered in a auto configuration way, instead of additionalPackages, because team A don't need to know the detail of shared modules and shared modules even don't share same parent package.

I want to implement something like:

//in spring-boot-starter-shared-modules.jar

@AutoConfiguration
class SharedModulesAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @AutoConfigureOrder(-1)
    public ApplicationModulesRuntime modulesRuntime(ApplicationRuntime runtime) {
        ThrowingSupplier<ApplicationModules> modules = () -> EXECUTOR
                .submit(() -> ApplicationModules.of(runtime.getMainApplicationClass()) //default implement
                    .merge(ApplicationModules.of("com.example.shared")))  // shared modules get registered
                .get();

        return new ApplicationModulesRuntime(modules, runtime);
    }
}

Moreover, shared modules should use EXPLICITLY_ANNOTATED ApplicationModuleDetectionStrategy, while modules in com.example.app keep using the default one - DIRECT_SUB_PACKAGES.

Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant