spring-projects / spring-projects/spring-modulith

Filter violations to gradually improve

Open
#489 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.2k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

When adding Spring Modulith to an existing codebase full of violations, the CustomApplicationModuleDetectionStrategy is a big help. However, I was faced with a failure of verify() because a service used field injection. Here it was just a single case and I solved it, but there are codebases where this is the standard way of injecting. Instead of verify in the test you might do something like this:

public void testModules() {

    Set<String> violations = ApplicationModules.of(Application.class).detectViolations().getMessages().stream()
            .filter(message -> !message.contains("uses field injection"))
            .collect(Collectors.toSet());

    Assertions.assertEquals(0, violations.size(), "There are violations:\n" + String.join("\n", violations));
}

In general, this could occur for all kind of violations you don't want to solve now

I see value to add verify(Predicate<String> filter) and detectViolations(Predicate<String> filter) , but maybe I miss a better solution here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ApplicationModules verification and violation-detection APIs mentioned in the issue, including verify() and detectViolations(). Compare the proposed predicate-based filtering with the existing violation reporting behavior. Done means callers can exclude selected violation messages while retaining zero-violation assertions for the remaining messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.