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 classes
of eachDependency
that originate from oneArchModule
and target anotherArchModule
reside 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 theModulesByAnnotationShould
property 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 theModulesByAnnotationShould
property namedannotationPropertyName
. This property *must* be of typeString[]
and contain thenames
of theArchModule
s 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 withinModulesByAnnotationShould
that declares allowed dependencies to otherArchModule
s by namedependencyScope
- Allows to adjust whichdependencies
are considered relevant by the rule- Returns:
- An
ArchRule
to be checked against a set ofJavaClasses
-
onlyDependOnEachOtherThroughPackagesDeclaredIn
@PublicAPI(usage=ACCESS, state=EXPERIMENTAL) ModulesByAnnotationRule<ANNOTATION> onlyDependOnEachOtherThroughPackagesDeclaredIn(String annotationPropertyName) Checks that thetarget classes
of eachDependency
that originate from oneArchModule
and target anotherArchModule
reside 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.SomeApi
would be allowed, but a dependency to a classcom.myapp.module_two.OutsideOfApi
would be forbidden.- Parameters:
annotationPropertyName
- The name of the property declared withinModulesByAnnotationShould
that defines through whichpackage identifiers
modules may depend on each other- Returns:
- An
ArchRule
to be checked against a set ofJavaClasses
-