Skip to content

OnionArchitecture: "withOptionalLayers" and "because" in the same statement causes that withOptionalLayers has no effect #1185

@pedrodelgado81

Description

@pedrodelgado81

Hi!
I wrote this statement

Architectures.onionArchitecture()
                .domainModels("com.myapp.domain.." )
		.applicationServices("com.myapp.application.port..","com.myapp.application.service..","com.myapp.application.usecase.." )
		.adapter( "adapters","com.myapp.adapters.." ) 
                .withOptionalLayers( true ).
		.because("SOME REASON").check( devClasses );

When I launched test, the output was: Layer 'domain service' is empty

If I remove because( ... ) statement all works fine.

Dependency info

 <dependency>
	<groupId>com.tngtech.archunit</groupId>
	<artifactId>archunit</artifactId>
	<version>1.1.0</version>
	<scope>test</scope>
</dependency>

Update: After debuggin I have seen that after call method public ArchRule because(String reason) optionalLayers variable changes from true to false.

Update 2: The problem is rule.as (ArchRule line 133) call that launch the creation of a new Onion Architecture (@publicapi(usage = ACCESS) ) but doesn't initialize the flag optionalLayers. It takes the default value (false).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions