Repository navigation
v0.18.0
After a long break, I'm bringing Konsist back up to date. This release fixes the most frequently reported issue: Kotlin 2.4. Make sure to check the Migration guide: 0.18.0 breaking changes.
In the AI era, code gets generated faster and in more varied structures than ever. I hope Konsist helps you keep your codebase consistent and your architecture in check.
Community Feedback & What's Next
My next focus is processing community feedback, and I plan to dedicate more time to the project going forward. Apologies for the long silence; life had to take priority for a while. Thanks for your patience and continued support.
Feedback is welcome again! Help shape the future of Konsist: what features would make your work easier? Which bugs are getting in your way? Share your ideas in the #konsist channel or Github Discussions. Your feedback helps us decide what to tackle next.
Please help spread the word: Konsist is back!
Big thanks goes to @nataliapeterwas and @aburmeis for the contributions.
Key changes
Kotlin 2.4
Konsist is now built with Kotlin 2.4.21.
Minimum requirements have changed:
0.17.3 |
0.18.0 |
|
|---|---|---|
| Kotlin | 1.8+ |
2.0+ |
| Java (JVM) | 8+ |
17+ |
Konsist still works when your project resolves an older Kotlin compiler at runtime (e.g. Kotlin 2.3 enforced via kotlin-bom).
Companion Object Support
Companion objects can now be verified with Konsist:
// Snippet
class A {
companion object
}
class B {
companion object CustomCompanion
}
class C
// Konsist test
Konsist
.scopeFromProject()
.classes()
.withCompanionObject() // [A, B]Use includeNested = true to also include companion objects of nested classes:
Konsist
.scopeFromProject()
.classes()
.companionObjects(includeNested = true)Case-Insensitive Name Matching
All name-based methods (hasName..., withName..., hasXWithName..., withXNamed..., etc.) now accept an ignoreCase parameter (default false). A new hasName method was added for exact name matching.
Konsist
.scopeFromProject()
.classes()
.withAnnotationNamed("sampleannotation", ignoreCase = true)
.assertTrue { it.hasNameContaining("sample", ignoreCase = true) }Annotation Source Declaration (⚠️ Breaking Change)
KoAnnotationDeclaration now provides sourceDeclaration, so annotation declarations can be verified directly:
Konsist
.scopeFromProduction()
.classes()
.annotations
.withSourceDeclaration { it.hasNameContaining("Sample") }
.assertTrue { ... }fullyQualifiedName of an annotation applied via an import alias now returns the real fully qualified name:
// Snippet
import com.domain.example.ExampleAnnotation as AnnotationAliased
@AnnotationAliased
class ExampleUseCase
// annotation.fullyQualifiedName
// Before: "AnnotationAliased"
// After: "com.domain.example.ExampleAnnotation"Enum Constant Improvements
Added ordinal property:
Konsist
.scopeFromProject()
.classes()
.withEnumModifier()
.enumConstants
.filter { it.name == "UNKNOWN" }
.assertTrue { it.ordinal == 0 }KoEnumConstantDeclaration now provides properties, functions and classes declared in the constant body. Variable and local declaration accessors are deprecated (removal planned for 0.20.0):
enumConstant.hasProperty { it.hasGetter } // previously hasVariable { ... }
enumConstant.hasFunction { it.hasReturnType() } // previously hasLocalFunction { ... }Architecture Assertions
Fixed strict dependency check reporting conflicts between unrelated layers:
// Before: throws "already defined with a strict=true value"
// After: passes
presentation.dependsOn(domain, strict = true)
data.dependsOn(domain)Layer documentation was updated to reflect the current package rules: .. wildcard is allowed at the start, middle or end of the package pattern.
Notable Bug Fixes
- Declarations are now resolved correctly for wildcard imports and Kotlin default imports (e.g.
hasParentOf(Throwable::class),hasAnnotationOf(RestController::class)withimport org.springframework.web.bind.annotation.*) typeArgumentsis now available for nullable types (e.g.List<String>?)parametersis now available for nullable function types (e.g.((String) -> Unit)?)isGenericnow returnstruefor types with nullable type arguments (e.g.List<String?>).gitdirectory is no longer scanned
Migration guide: 0.18.0 breaking changes
Other breaking changes are covered in Key changes: minimum Kotlin 2.0 / Java 17, and fullyQualifiedName of import-aliased annotations.
APIs deprecated in earlier releases have been removed. Properties on declarations (isNullable, isTopLevel and so on) work the same. Only code that refers to the old provider types or the removed list extensions needs changes.
Provider interfaces
| Removed | Use instead |
|---|---|
KoNullableProvider |
KoIsNullableProvider |
KoGenericTypeProvider |
KoIsGenericProvider (isGeneric) |
KoConstructorDefinedProvider |
KoIsConstructorDefinedProvider |
KoWildcardProvider |
KoIsWildcardProvider |
KoInitializerProvider |
KoIsInitializedProvider |
KoReadOnlyProvider |
KoIsReadOnlyProvider |
KoTopLevelProvider |
KoIsTopLevelProvider |
List extensions
| Removed | Use instead |
|---|---|
withNullableType() |
withNullable() |
withoutNullableType() |
withoutNullable() |
Complete List Of Changes
⚠️ Breaking API Changes
- KON-704 Add source declarations to
KoAnnotationDeclarationby @igorwojda in #1829 - Raise minimum Kotlin version from
1.8to2.0by @igorwojda in #1891 - Raise minimum Java version from
8to17by @igorwojda- Fix Build (Upgrade Kotlin version and make Konsist artifact compatible with Java 11) by @igorwojda in #1799
- Upgrade Konsist JVM target from
11to17by @igorwojda in #1903
- Remove APIs deprecated for removal in
0.18.0by @igorwojda in #1910 (see Migration guide)
🐛 API Bug Fixes
- KON-701 Fix incorrect sourceDeclaration resolution for inner classes in parent declarations by @nataliapeterwas in #1621
- KON-707 Fixed identification of declarations when using wildcard imports or Kotlin classes from default imports by @igorwojda in #1813
- KON-710 Fix bug where searching for parameters in KoFunctionTypeDeclarationProvider failed when the type was nullable by @igorwojda in #1840
- KON-712 Fix bug when
typeArgumentsis not available for nullable parameters by @igorwojda in #1843 - KON-702 Fix Strict Override Check Ignoring Layer Match by @aburmeis in #1870
💡 API Improvements
- KON-695 Add missing providers for
KoEnumConstantDeclarationby @nataliapeterwas in #1618 - KON-682 Add ignoreCase parameter to "withName..." and "hasName..." methods by @nataliapeterwas in #1571
- KON-689 Add support for companion objects by @igorwojda in #1841
- Add ordinal property to enum constant declaration by @igorwojda in #1905
💡 Improvements
- Upgrade Kotlin to 2.4.21 (Java 25 support) by @igorwojda in #1891
- Support Kotlin < 2.4 Compiler At Runtime by @igorwojda in #1899
- KON-709 Konsist should not scan .git/ by @igorwojda in #1847
📕 Documentation
- Update Kdocs by @igorwojda in #1895
- Remove Dokka API reference link from README by @igorwojda in #1901
🏗️ Maintenance
- Fix Test Logger by @igorwojda in #1696
- Clean up
spotlessconfig by @igorwojda in #1800 - Update sample projects by @igorwojda in #1801
- Revert "Update junit-framework monorepo to v6 (major)" by @igorwojda in #1817
- Block Major Java Updates by @igorwojda in #1821
- Move deps to toml by @igorwojda in #1822
- Move Build logic from buildSrc to buildLogic module by @igorwojda in #1824
- Move Stuff from top level to misc by @igorwojda in #1825
- Rename
buildLogictobuild-logicby @igorwojda in #1827 - Add cline rules by @igorwojda in #1828
- Disable Dokka by @igorwojda in #1876
- Update Spotless Config by @igorwojda in #1882
- Update starter projects dependencies by @igorwojda in #1888
- Upgrade Jvm Toolchain by @igorwojda in #1892
- Update Spring Starter Projects To Kotlin 2.4.21 by @igorwojda in #1900
- Extract test project checks into separate workflow by @igorwojda in #1904
- KON-639 Rename
SampletoFixturein test code by @igorwojda in #1907 - Check only changed kttest snippets in CI by @igorwojda in #1908
- Update Konsist version from
0.17.3to0.18.0by @igorwojda in #1909 - Dependency updates by @renovate
Full Changelog: v0.17.3...v0.18.0