https://kotlinlang.org logo
Join Slack
Powered by
# konsist
  • p

    Peter

    10/22/2024, 12:08 PM
    Hey, I'm a bit confused, how to check for cyclic dependencies. I have following rules, but even though cyclic dependency exists in code, assert doesn't fail.
    Copy code
    Konsist.scopeFromModule("app")
        .assertArchitecture {
            val profile = Layer("profile", "com.some.app.profile..")
            val auth = Layer("auth", "com.some.app.auth..")
            profile.dependsOn(auth)
            auth.dependsOn(profile)
        }
    g
    • 2
    • 2
  • b

    Blaž Vantur

    10/23/2024, 8:07 AM
    I wrote konsist test for checking how feature folders(modules) depend on each other in the project. Each feature folder should depend only on the core feature and not on other features. I am curious if any of you guys had a need to write such a test and how you did it. Or if it makes sense at all to have such a test in place. Check the code in the thread 🧵
    i
    • 2
    • 3
  • t

    Tim Malseed

    10/24/2024, 11:35 AM
    I wonder if Konsist could be the right tool to help detect potential unhandled exceptions in certain layers. For example, a ViewModel that, tracing the call hierarchy, doesn’t handle a network exception..
    p
    i
    • 3
    • 3
  • i

    igor.wojda

    10/25/2024, 11:56 AM
    Hey amazing community. Next release is coming soon. In the mean time it looks like Konsist is on the right track 🎉 Star it UP if you haven't done so already 🌟🙏
    ❤️ 9
  • n

    Natalia Peterwas

    10/28/2024, 12:10 PM
    The Konsist icon have been added to Slack - every tiny detail matters 🙃 👇
    konsist 10
  • d

    Dominik

    10/30/2024, 10:11 AM
    Hi, I am looking into Konsist and trying to figure out following scenario I have a simple class
    FooClass
    and an enum
    BarEnum
    .
    Copy code
    class FooClass {
        val enum: BarEnum = BarEnum.BAR
    }
    
    enum class BarEnum {
        BAR
    }
    Now what I need to figure out is: Does
    FooClass
    contain a property of any
    Enum
    type? Happy for any ideas/input.
    b
    p
    +2
    • 5
    • 15
  • e

    Eugen Martynov

    11/04/2024, 10:13 AM
    Oke, if I have lint rule I can share it between modules, how to achieve same with konsist?
    ☝️ 1
    p
    i
    • 3
    • 5
  • y

    Yerdaulet

    11/22/2024, 7:32 AM
    Hello, I want to check whether method of interface return type is equal to value wrapped to my own generic value
    Copy code
    //thing to check
    suspend fun getAccounts(
        @Query("account") account: String,
    ): ApiResult<AccountDto>
    Copy code
    //test 
    apiInterfacesScope
                    .assertTrue {
                        it.hasFunction { function ->
                            function.returnType?.asInterfaceDeclaration()?.name == "ApiResult"
                        }
                    }
    but my code doesn't work
    p
    • 2
    • 1
  • r

    Rasmus Larsen

    11/22/2024, 12:30 PM
    Hi 🙂 I want to ensure that all classes and functions within a specific package aren't public. I thought I could use
    hasPublicOrDefaultModifier
    for this. But functions within an internal class will return hasPublicOrDefaultModifier=true. Is there anything I can do to test this? Code sample added in comments.
    p
    • 2
    • 11
  • i

    igor.wojda

    11/25/2024, 10:23 AM
    👉 Konsist 0.17.0 has been released. Key Changes • Improve backwards compatibility (up to Kotlin 1.8) • Add Support for Generic type parameters and generic type arguments • Fixed APIs around parent verification - allow to verify use side (now possible) and declaration site (API has changed a bit) • Improved architecture assertions • Improved test failure output formatting • The Konsist Language reference was added • Various API Improvements See full release log https://github.com/LemonAppDev/konsist/releases/tag/v0.17.0
    konsist 6
    🎉 5
    thank you color 5
    b
    • 2
    • 6
  • m

    Mario Niebes

    11/26/2024, 3:47 PM
    It seems like
    dependsOn
    is now (v0.17.0) changed from "may depend on" to "has to depend on". Is this intended?
    i
    • 2
    • 5
  • i

    igor.wojda

    11/30/2024, 7:47 PM
    Konsist documentation now shows different ways to check and verify code declarations: https://docs.konsist.lemonappdev.com/veryfying-codebase/verify-classes
    🤩 3
    K 5
    konsist 6
  • i

    igor.wojda

    12/02/2024, 4:53 PM
    Konsist 0.17.1 has been released https://github.com/LemonAppDev/konsist/releases/tag/v0.17.1
    🙏 3
    konsist 2
  • a

    Amitoj Duggal

    12/04/2024, 11:22 AM
    Hello team 👋 , we recently tried updating to 0.17.1 our older tests started failing with the following error
    Copy code
    Invalid package definition for layer 'Adapter DTOs'. Package can only end with '..'
    We have layers defined like this, which worked well with 0.16
    Copy code
    val adapterDtos = Layer("Adapter DTOs", "$basePackage.adapter..dto..")
    I see that some package-related changes were reverted in 0.17.1. Though this seems to be the current behaviour, is it an intended breaking change?
    i
    • 2
    • 2
  • e

    Eric

    12/18/2024, 2:59 PM
    Is there a better way of doing this other than checking
    toString
    ?
    Copy code
    @MethodSource("entityClasses")
        @ParameterizedTest(name = "test {1} child collections that are not an immutable Set have @OneToMany(orphanRemoval = true)")
        fun `test entities mutable child collections have @OneToMany(orphanRemoval = true)`(
            entityClass: Class<*>,
            className: String,
        ) {
            expectThat(entityClass.kotlin.declaredMemberProperties)
                .filter { it.returnType.isSubtypeOf(Collection::class.starProjectedType) }
                .filterNot { it.returnType.toString().startsWith("kotlin.collections.Set") }
                .map { requireNotNull(it.javaField).getAnnotation(OneToMany::class.java) }
                .all { get { orphanRemoval }.isTrue() }
        }
    i
    • 2
    • 2
  • b

    buszi0809

    12/23/2024, 8:44 AM
    Hi, I think I've encountered a breaking issue for me when migrating from Konsist version
    0.15.1
    to
    0.17.3
    and wanted to confirm it is not an issue on my side I have a test case where I verify that classes that have UseCase as parent interface reside in
    .impl
    package of this parent interface, basically verifying that use case implementations are placed in correct package in relation to the interface definition before migration it looked like this:
    Copy code
    Konsist.scopeFromProject()
        .classes()
        .withParent { it.hasNameEndingWith("UseCase") }
        .assertTrue { impl ->
            val parent = impl.parents().first { it.hasNameEndingWith("UseCase") }
            impl.resideInPackage(parent.packagee?.fullyQualifiedName + ".impl")
        }
    now from what I've understood it should look like this:
    Copy code
    Konsist.scopeFromProject()
        .classes()
        .withParentInterface { it.hasNameEndingWith("UseCase") }
        .assertTrue { impl ->
            val parent = impl.parentInterfaces().first { it.hasNameEndingWith("UseCase") }
            impl.resideInPackage(parent.packagee?.name + ".impl")
        }
    but those tests are failing now, I've printed some values and it seems that the issue is that the parent's package has wrong value that is inherited from the implementation class so basically let's say that we have
    ExampleUseCaseImpl
    in
    com.example.impl
    , and the parent interface is named
    ExampleUseCase
    in
    com.example
    , it seems that the parent found with
    val parent = impl.parentInterfaces().first { it.hasNameEndingWith("UseCase") }
    has package name value
    com.example.impl
    instead of
    com.example
  • j

    Josef N.

    01/13/2025, 10:37 AM
    Hello, I am trying to replace archunit with konsist in legacy codebase where we are trying to adapt KMP, but considering we have circular dependencies between layers (which are ok in archunit), it keeps failing in Konsist. So the question is - are cicular dependencies in
    assertArchitecture
    block supposed to be ok or not
    ? In arch snippets you have this: https://docs.konsist.lemonappdev.com/inspiration/snippets/architecture-snippets
    Copy code
    presentation.dependsOn(business)
                business.dependsOn(presentation)
    but in tests it is supposed to throw exception. Even this specific snippet fails when ran: https://docs.konsist.lemonappdev.com/inspiration/snippets/architecture-snippets#id-1.-2-layer-architecture-has-correct-dependencies
    Circular dependency detected: 'Presentation' <-> 'Business'.
    I've tried with version 0.17.3
  • j

    Jan Janovec

    01/21/2025, 8:42 AM
    Hi everyone, 👋 I’m new to Konsist and currently working on a project with multiple modules. I’d like to integrate Konsist into my workflow. While setting up, I’m trying to isolate tests in my shared module. However, I couldn’t find the Kotlin Multiplatform Shared Module Template in the module creation wizard. I haven’t created a module manually before, so I’d appreciate guidance on how to set this up. Thanks in advance for your help! 🙏
    i
    • 2
    • 1
  • i

    Ivan Varga

    01/29/2025, 9:22 AM
    Hi Konsist community! 👋 I have recently started working with Konsist and loving it! However, I've stumbled upon one issue I cannot figure out so any help is very much appreciated. I have a ViewModel defined as:
    Copy code
    class MyViewModel(
        private val a: A?,
        backgroundCoroutineScope: BackgroundCoroutineScope,
    ) : ViewModel(viewModelScope = backgroundCoroutineScope.scope)
    and a Unit test with Konsist:
    Copy code
    Konsist.scopeFromProject()
                .classes()
                .withParentOf(ViewModel::class)
                .withName { it.equals("MyViewModel", ignoreCase = true) }
                .withPrimaryConstructor()
                .properties()
                .print()
    The
    print
    statement you see above, prints only
    a
    , but not
    backgroundCoroutineScope
    . I assume this is due to the
    backgroundCoroutineScope
    not being a var nor a val. Is there a way I can verify that this constructor property exists? Thank you 🙏
    v
    • 2
    • 6
  • m

    Mark Murphy

    02/03/2025, 6:50 PM
    Hi! 👋 The Konsist documentation has some diagrams (Mermaid?) that seem broken. For example, the Getting Started page has a diagram where 4 of the 6 boxes have "Unsupported markdown: list" (see attached screenshot). The create-first-test page has a diagram where all 4 of the boxes show that error. I am seeing this with multiple browsers and operating systems, so AFAICT it is a legit problem.
    plus1 1
    i
    • 2
    • 2
  • i

    itumeleng

    02/17/2025, 3:13 PM
    Hey Everyone, are we able to use Konsist to test gradle files? e.g write tests to verify all modules' release build variants have minifyEnabled set to true?
    m
    • 2
    • 2
  • d

    dead.fish

    02/18/2025, 12:52 PM
    Hi all, I'm new to Konsist and try to think about how to integrate konsist checks in a multi component repository that has multiple apps that should follow roughly the same guidelines. My idea was to write a build convention that adds a runtime dependency onto several
    <component>/konist-checks
    modules and this runtime dependency would contain the actual (dynamic) tests. The build convention would also be configurable so that I could change the execution environment of the tests, e.g. by disabling tests that are irrelevant for some components, filtering out legacy Gradle library modules that should not be checked, aso. asf. Would that be a feasible approach or how do people "scale" konsist otherwise?
  • a

    Ali Kabiri

    02/26/2025, 10:23 AM
    Hi everyone, I'm new to Konsist since the last droidcon and loving it so far. Recently I wanted to use Konsist (v0.17.3) to check non-default constructor method calls for
    MutableSharedFlow
    in my code. An example in simple words:
    MutableSharedFlow()
    is correct, but
    MutableSharedFlow(replay = 1)
    is incorrect. To test the filtering of non-default calls, I wrote the following code:
    Copy code
    val sut = Konsist.scopeFromProject()
        .files
        .withTextMatching(""".*MutableSharedFlow.*\(.+\)""".toRegex())
    
    println(sut.size)
    However, the result of
    sut.size
    is zero, but there are more than 10 occurrences in my files. I am curious to know if that is the right way to use regular expressions with Konsist because I couldn't find any examples of it in the docs. Could anyone help me with using regular expressions and Konsist?
    • 1
    • 1
  • b

    Berkay Özkan

    03/03/2025, 6:57 AM
    Hi, im new to konsist and wondering is assertTrue mandatory? can we use something like kotest matchers
    Copy code
    Konsist
          .scopeFromProduction()
          .files
          .forEach {
            it.text.isEmpty() shouldBe false
          }
    p
    • 2
    • 7
  • r

    rocketraman

    03/04/2025, 2:31 PM
    Hello! Trying to declare an architecture test with a package. Getting the error message
    Invalid package definition for layer 'Core'. To include subpackages, the definition must end with '..'. Current definition: foo.core
    . But I don't want to include sub-packages so the declaration should be correct. My full use case is this:
    Copy code
    val core = Layer("Core", "foo.core")
    val coreApi = Layer("CoreApi", "foo.core.api..")
    Konsist.scopeFromProduction()
      .assertArchitecture {
        core.dependsOn(coreApi)
        coreApi.dependsOnNothing()
      }
    but this test fails because
    foo.core
    is an invalid package definition, and using
    foo.core..
    includes
    core.api
    .
    • 1
    • 1
  • d

    David Rubio

    03/12/2025, 9:37 PM
    Hello. I'm new to Konsist. I want to find classes in my library module that are only used inside that module but are not marked as
    internal
    . Can this tool do that?
    👀 1
  • m

    Max

    03/18/2025, 7:37 PM
    Hello! I'm just trying Konsist. I've added sample test to my project:
    Copy code
    class SampleKonsistTest : FreeSpec({
        "android activity class name ends with 'Activity'" {
            Konsist
                .scopeFromProject()
                .classes()
                .withAllParentsOf(ComponentActivity::class)
                .assertTrue { it.name.endsWith("Activity") }
        }
    })
    and dependencies:
    Copy code
    testImplementation("com.lemonappdev:konsist:0.17.3")
    testImplementation("io.kotest:kotest-runner-junit5:5.9.1")
    But when I'm trying to run this test I'm getting the error:
    Copy code
    Execution failed for task ':app:testDebugUnitTest'.
    > No tests found for given includes: [com.example.polygone.SampleKonsistTest](--tests filter)
    Could somebody help me to understand, what I'm doing wrong?
  • m

    Max

    04/13/2025, 2:16 PM
    Hello! I have a question about
    Layer rootPackage must be unique
    rule. I have many feature-modules in my project, and each feature module divided to api and impl submodules. So I have layers like:
    Copy code
    val featureApi = Layer("FeatureApi", "com.example..feature..api.."),
    val featureImpl = Layer("FeatureImpl", "com.example..feature..impl..")
    I want to check, that my impl modules don't depend on other impl modules. But I can't just do like this:
    Copy code
    featureImpl.doesNotDependOn(featureImpl)
    and even
    Copy code
    featureImpl.doesNotDependOn(featureImpl.copy(name = "OtherFeatureImpl"))
    So, question: Does my case supported in Konsist and how can I make this check?
    v
    • 2
    • 2
  • m

    Michał Doliński

    05/06/2025, 8:55 PM
    Hi! I'm wondering if you know what are the plans for Konsist project? Like, I see (or at least get an impression) that activity is decreasing. Looking at the roadmap its already 3 quarters behind the schedule. I'm considering using it in my projects but I'm not convinced if its a good idea, having the points above in mind.
    k
    i
    • 3
    • 5
  • r

    Rasmus Larsen

    05/28/2025, 8:52 AM
    Hi 🙂 Would it be possible to create a scope of all modules ending with, eg. "-ui"?
    • 1
    • 1