Skip to content

Spring Modulith reports ambiguous violation message in case when @Modulithic#sharedModules and @ApplicationModule#allowedDependencies attributes are used #1778

Description

@nikolamicic21

Issue

Spring Modulith reports ambiguous violation message

Module 'bidding' depends on module 'review' via com.example.demo.bidding.BidService -> com.example.demo.review.analysis.AnalyzerService. Allowed targets: review.

Demo

no module
root package - com.example.demo

com.example.demo.DemoApplication.java

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.modulith.Modulithic;

@SpringBootApplication
@Modulithic(
        sharedModules = {"review"}
)
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

module - bidding
root package - com.example.demo.bidding

com.example.demo.bidding.package-info.java

@ApplicationModule(
        allowedDependencies = {}
)
package com.example.demo.bidding;

import org.springframework.modulith.ApplicationModule;

com.example.demo.bidding.BidService.java

package com.example.demo.bidding;

import com.example.demo.review.analysis.AnalyzerService;
import org.springframework.stereotype.Service;

@Service
public class BidService {

    private final AnalyzerService analyzerService;

    public BidService(AnalyzerService analyzerService) {
        this.analyzerService = analyzerService;
    }
}

module - review
root package - com.example.demo.review

com.example.demo.review.package-info.java

@ApplicationModule(
        //type = ApplicationModule.Type.OPEN,
        allowedDependencies = {}
)
package com.example.demo.review;

import org.springframework.modulith.ApplicationModule;

com.example.demo.review.analysis.AnalyzerService.java

package com.example.demo.review.analysis;

import org.springframework.stereotype.Service;

@Service
public class AnalyzerService {
}

With this setup, on ApplicationModules.of(DemoApplication.class).verify(), the following violation message is printed

Module 'bidding' depends on module 'review' via com.example.demo.bidding.BidService -> com.example.demo.review.analysis.AnalyzerService. Allowed targets: review.

Expected behavior

The violation message is ambiguous, it doesn't clearly states what is the problem. It should be something like

Module 'bidding' depends on non-exposed type com.example.demo.review.analysis.AnalyzerService within module 'review'!

because, as soon as we uncomment the line //type = ApplicationModule.Type.OPEN, in the com.example.demo.review.package-info.java, the verification is successfully passing.

Demo project attached below

demo.zip

Metadata

Metadata

Assignees

Labels

in: coreCore module meta modeltype: bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions