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

Verification on empty project failing #520

Closed
pmikulicLayer opened this issue Feb 28, 2024 · 1 comment
Closed

Verification on empty project failing #520

pmikulicLayer opened this issue Feb 28, 2024 · 1 comment
Assignees
Labels
in: core Core module meta model type: improvement Minor improvements
Milestone

Comments

@pmikulicLayer
Copy link

pmikulicLayer commented Feb 28, 2024

I Have Spring boot 3.2.3 project with Java 21.

In pom.xml I have
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.modulith</groupId> <artifactId>spring-modulith-bom</artifactId> <version>${version.spring-modulith-bom}</version> <type>pom</type> <scope>import</scope> </dependency>

<dependency> <groupId>org.springframework.modulith</groupId> <artifactId>spring-modulith-core</artifactId> </dependency>
<dependency> <groupId>org.springframework.modulith</groupId> <artifactId>spring-modulith-starter-test</artifactId> <scope>test</scope> </dependency>

I am running test:
`
class ApplicationModularityUnitTest {

ApplicationModules modules = ApplicationModules.of(Application.class);

@Test
void verifiesModularStructure() {
    modules.verify();
}`


But error is:
`

java.lang.AssertionError: Rule 'slices assigned from Appliction module slices [] should be free of cycles' failed to check any classes. This means either that no classes have been passed to the rule at all, or that no classes passed to the rule matched the that() clause. To allow rules being evaluated without checking any classes you can either use ArchRule.allowEmptyShould(true) on a single rule or set the configuration property archRule.failOnEmptyShould = false to change the behavior globally.

at com.tngtech.archunit.lang.ArchRule$Factory$SimpleArchRule.verifyNoEmptyShouldIfEnabled(ArchRule.java:201)
at com.tngtech.archunit.lang.ArchRule$Factory$SimpleArchRule.evaluate(ArchRule.java:181)
at com.tngtech.archunit.lang.syntax.ObjectsShouldInternal.evaluate(ObjectsShouldInternal.java:76)
at com.tngtech.archunit.library.dependencies.SliceRule.evaluate(SliceRule.java:99)
at org.springframework.modulith.core.ApplicationModules.assertNoCyclesFor(ApplicationModules.java:462)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:722)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.springframework.modulith.core.ApplicationModules.detectViolations(ApplicationModules.java:368)
at org.springframework.modulith.core.ApplicationModules.verify(ApplicationModules.java:346)
at eu.layer.labcontrol.ApplicationModularityUnitTest.verifiesModularStructure(ApplicationModularityUnitTest.java:18)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)`

I changed the Spring Boot version from 3.0.7 to 3.2.3, the Java version from 17 to 21 and

@odrotbohm
Copy link
Member

I have a hard time reproducing this on a standard Spring Boot arrangement, as the Application class you point to should at least be included in the classes to be verified. In other words, there shouldn't be a case in which the set of classes to be inspected should be empty unless you point to a non-existant package in the first place. I can see that the currently thrown exception could be improved, but ultimately, I think that rejecting such a scenario right away is indeed better than just ignoring the problem, as it's definitely an incorrect setup.

I'll put measures in place that will reject the latter case with a better error message. If you can provide a reproducer for the standard bootstrap case (pointing to a Spring Boot application class) I'm happy to look at that, too.

@odrotbohm odrotbohm changed the title Verify structure Verification on empty project failing Mar 5, 2024
@odrotbohm odrotbohm self-assigned this Mar 5, 2024
@odrotbohm odrotbohm added in: core Core module meta model type: improvement Minor improvements labels Mar 5, 2024
@odrotbohm odrotbohm added this to the 1.2 M3 milestone Mar 5, 2024
odrotbohm added a commit that referenced this issue Mar 5, 2024
We now immediately reject the ApplicationModules bootstrap in case the initial scanning of the root packages yield no classes at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core module meta model type: improvement Minor improvements
Projects
None yet
Development

No branches or pull requests

2 participants