Package Wildcard
Select packages
Package wildcard syntax is used to provide a more flexible way of querying packages.
The two dots (..) mean zero or more packages, e.g. all classes reside in a package starting with com.app:
Konsist
.scopeFromProject()
.classes()
.assertTrue { it.residesInPackage("com.app..") }
// com.app - valid
// com.app.data - valid
// com.app.data.repository - valid
// com.data - invalid
// com - invalid
Package wildcard syntax can be used multiple times inside the string argument. Here all interfaces reside in a package logger prefixed and suffixed by any number of packages:
Konsist
.scopeFromProject()
.interfaces()
.assertTrue { it.residesInPackage("..logger..") }
// logger - valid
// com.logger - valid
// com.logger.tree - valid
// com - invalidPackage without .. must match exactly (case-insensitive), e.g. residesInPackage("com.app") is false for a declaration in the com.app.data package. The .. wildcard can also be used between packages, e.g. com..data matches com.data and com.app.data.
Last updated