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

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

Closed
pedrodelgado81 opened this issue Nov 3, 2023 · 2 comments · Fixed by #1226
Assignees

Comments

@pedrodelgado81
Copy link

pedrodelgado81 commented Nov 3, 2023

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).

@codecholeric
Copy link
Collaborator

Thanks for raising the issue and providing the analysis!! You're right, this must have been an oversight when the flag was added 🙈 I tried to fix it in #1226 if you want to take a look...

@pedrodelgado81
Copy link
Author

Thanks for the work! ;)

codecholeric added a commit that referenced this issue Mar 24, 2024
The `OnionArchitecture.as(..)` method (and transitively `because(..)`)
didn't pass the `optionalLayers` property along when creating a `new
OnionArchitecture(..)` on return. Thus, once a test called `as(..)` or
`because(..)` on the rule text `optionalLayers` would be reset to
`false`.

Resolves: #1185
@codecholeric codecholeric changed the title OnionArchitecture: "withOptionalLayers" and "because" in the same statement casues that withOptionalLayers has no effect OnionArchitecture: "withOptionalLayers" and "because" in the same statement causes that withOptionalLayers has no effect Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants