ArchUnit 0.14.1 没有检测到用作通用字段参数的类型的循环依赖关系。这是 ArchUnit 的限制还是我做错了什么?,例如:
package com.test.a;
import com.test.b.B;
public class A {
protected B b;
}
package com.test.b;
import java.util.Optional;
import com.test.a.A;
public class B {
protected Optional<A> a; // not detected by archunit
// protected A a2; // detected by archunit
}
@AnalyzeClasses(packages = "com.test")
public class ArchitecturalChecks {
@ArchTest
public void testNoCycles(JavaClasses importedClasses) {
SlicesRuleDefinition.slices().matching("com.test.(*)..").should().beFreeOfCycles().check(importedClasses);
}
@ArchTest
public void testPackageStructure(JavaClasses importedClasses) {
// @formatter:off
Architectures.layeredArchitecture()
.layer("A").definedBy("com.test.a..")
.layer("B").definedBy("com.test.b..")
.whereLayer("A").mayNotBeAccessedByAnyLayer()
.whereLayer("B").mayOnlyBeAccessedByLayers("A")
.check(importedClasses);
// @formatter:on
}
}