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

Detecting access to static variables as dependencies in slices #1115

Closed
Azahe opened this issue May 30, 2023 · 2 comments
Closed

Detecting access to static variables as dependencies in slices #1115

Azahe opened this issue May 30, 2023 · 2 comments

Comments

@Azahe
Copy link

Azahe commented May 30, 2023

Given actual example from our codebase:

  @Test
  void actionPackagesShouldNotDependOnEachOther() {
    SlicesRuleDefinition.slices()
      .matching("kontox.lib.internal.actions.(*)..")
      .should().notDependOnEachOther()
      .check(allLibClasses);
  }

I would expect that if I reference public static variable from one of the slices in the other slice - that would cause a rule violation.

It doesn't.

Detecting other dependencies (like method calls) works.

Is it intentional?

@hankem
Copy link
Member

hankem commented May 30, 2023

Is it a static final String or primitive constant? Those are not referenced as dependencies in the byte code, but just inlined in the constant pool of the class that uses it, cf. #298 (comment), which is why ArchUnit unfortunately currently cannot detect them. But as these are actually no runtime dependencies, cf. #298 (comment), it might be okayish to not have a violation for them?

@Azahe
Copy link
Author

Azahe commented May 30, 2023

It indeed is a String... thanks for the response and I guess sorry for not finding the answer myself.

In regards to this behavior being okayish - it is not a tragedy, but mostly because static final fields are easy to move around.
We aim to have those packages to simulate completely separate "modules" and slowly push the architecture in that direction over time - so even compile-time dependencies mean that at some point in future we will have to eliminate them (we hoped that arch unit will help us make sure that, at least, no new violations will be introduced).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants