Interface ModulesByAnnotationShould<ANNOTATION extends Annotation>
- All Superinterfaces:
ModulesShould<AnnotationDescriptor<ANNOTATION>>
@PublicAPI(usage=ACCESS,
state=EXPERIMENTAL)
public interface ModulesByAnnotationShould<ANNOTATION extends Annotation>
extends ModulesShould<AnnotationDescriptor<ANNOTATION>>
-
Method Summary
Modifier and TypeMethodDescriptiononlyDependOnEachOtherThroughPackagesDeclaredIn(String annotationPropertyName) Checks that thetarget classesof eachDependencythat originate from oneArchModuleand target anotherArchModulereside in a package that matches a package identifier declared withinModulesByAnnotationShould.respectTheirAllowedDependenciesDeclaredIn(String annotationPropertyName, ModuleDependencyScope dependencyScope) LikeModulesShould.respectTheirAllowedDependencies(DescribedPredicate, ModuleDependencyScope), but the allowed dependencies will be automatically derived from theModulesByAnnotationShouldproperty namedannotationPropertyName.Methods inherited from interface com.tngtech.archunit.library.modules.syntax.ModulesShould
beFreeOfCycles, onlyDependOnEachOtherThroughClassesThat, onlyDependOnEachOtherThroughClassesThat, respectTheirAllowedDependencies, respectTheirAllowedDependencies
-
Method Details
-
respectTheirAllowedDependenciesDeclaredIn
@PublicAPI(usage=ACCESS, state=EXPERIMENTAL) ModulesByAnnotationRule<ANNOTATION> respectTheirAllowedDependenciesDeclaredIn(String annotationPropertyName, ModuleDependencyScope dependencyScope) LikeModulesShould.respectTheirAllowedDependencies(DescribedPredicate, ModuleDependencyScope), but the allowed dependencies will be automatically derived from theModulesByAnnotationShouldproperty namedannotationPropertyName. This property *must* be of typeString[]and contain thenamesof theArchModules to which access is allowed.
For example, given the user-defined annotation
and the annotated root classes@interface MyModule { String name(); String[] allowedDependencies() default {}; }
Then the allowed dependencies between the modules would be@MyModule(name = "Module One", allowedDependencies = {"Module Two", "Module Three"}) interface ModuleOneDescriptor {} @MyModule(name = "Module Two", allowedDependencies = {"Module Three"}) interface ModuleTwoDescriptor {} @MyModule(name = "Module Three") interface ModuleThreeDescriptor {},----------. |Module One| ------------. `----------' \ | | | | v v ,----------. ,------------. |Module Two| ------> |Module Three| `----------' `------------'- Parameters:
annotationPropertyName- The name of the property declared withinModulesByAnnotationShouldthat declares allowed dependencies to otherArchModules by namedependencyScope- Allows to adjust whichdependenciesare considered relevant by the rule- Returns:
- An
ArchRuleto be checked against a set ofJavaClasses
-
onlyDependOnEachOtherThroughPackagesDeclaredIn
@PublicAPI(usage=ACCESS, state=EXPERIMENTAL) ModulesByAnnotationRule<ANNOTATION> onlyDependOnEachOtherThroughPackagesDeclaredIn(String annotationPropertyName) Checks that thetarget classesof eachDependencythat originate from oneArchModuleand target anotherArchModulereside in a package that matches a package identifier declared withinModulesByAnnotationShould.
For example, given the annotation
and the annotated root classes@interface MyModule { String name(); String[] exposedPackages() default {}; }
Then a dependency from Module One to a class@MyModule(name = "Module One") interface ModuleOneDescriptor {} @MyModule(name = "Module Two", exposedPackages = {"com.myapp.module_two.api.."}) interface ModuleTwoDescriptor {}com.myapp.module_two.api.SomeApiwould be allowed, but a dependency to a classcom.myapp.module_two.OutsideOfApiwould be forbidden.- Parameters:
annotationPropertyName- The name of the property declared withinModulesByAnnotationShouldthat defines through whichpackage identifiersmodules may depend on each other- Returns:
- An
ArchRuleto be checked against a set ofJavaClasses
-