Hi! I am trying to test this library. But it seems...
# akkurate
m
Hi! I am trying to test this library. But it seems like i cannot get the variable (property) from data class? From the docs i should get this ..?
j
Hi @mudasar187, thank you for trying Akkurate 🙂
You have to build your project to trigger code generation: https://akkurate.dev/docs/harness-the-dsl.html#access-properties
m
Ah off course, sorry my bad 🙂
j
no worries
m
So the moment i add @Validate i need to build the project to trigger code generation to get the constraint to work?
j
In the future, I will write a compiler plugin that will allow to skip the "build your project first" part
yes 👍
m
AH yeah, that would be amazing!
CleanShot 2024-12-12 at 10.44.46.png
I have added this as plugin
Copy code
id("com.google.devtools.ksp") version "2.1.0-1.0.29"
and deps
Copy code
// Akkurate
    implementation("dev.nesk.akkurate:akkurate-core:0.11.0")
    ksp("dev.nesk.akkurate:akkurate-ksp-plugin:0.11.0")
If i remove these, the build get successful
j
I you leave the ksp plugin but remove the akkurate dependencies, do you still encounter this error?
m
Removing these
Copy code
// Akkurate
    implementation("dev.nesk.akkurate:akkurate-core:0.11.0")
    ksp("dev.nesk.akkurate:akkurate-ksp-plugin:0.11.0")
but leaving the plugin added it get successful build
j
OK, so the issue is with this line:
Copy code
ksp("dev.nesk.akkurate:akkurate-ksp-plugin:0.11.0")
I see the
ktlinFormat
task is triggered by the
kspKotlin
one, and I don't think this is necessary.
I don't know how ktlint works, it seems like you have to add the following code to your build? Did you do this?
Copy code
tasks.register<JavaExec>("ktlintFormat") {
    group = LifecycleBasePlugin.VERIFICATION_GROUP
    description = "Check Kotlin code style and format"
    classpath = ktlint
    mainClass.set("com.pinterest.ktlint.Main")
    jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
    // see <https://pinterest.github.io/ktlint/install/cli/#command-line-usage> for more information
    args(
        "-F",
        "**/src/**/*.kt",
        "**.kts",
        "!**/build/**",
    )
}
m
I have this in my config
Copy code
tasks {
    named("runKtlintCheckOverMainSourceSet").configure {
        dependsOn("graphqlGenerateClient")
        dependsOn("openApiGenerate")
    }

    named("runKtlintFormatOverMainSourceSet").configure {
        dependsOn("graphqlGenerateClient")
        dependsOn("openApiGenerate")
    }

    withType<KotlinCompile>().configureEach {
        dependsOn("ktlintFormat")
        dependsOn("graphqlGenerateClient")
        dependsOn("openApiGenerate")
    }
j
Yeah, that's the issue, you have to add an exclusion to the dependencies of the ktlint tasks. Let me explain briefly to help you understand so you can find a solution. KSP is a tool (developed by Google) that allows developers (like me 😛 ) to easily write compiler plugins. I wrote one for Akkurate, it generates code for the classes annotated with
@Validated
. The issue here is that ktlint tries to format the code generated by KSP (and, more specifically, by Akkurate). You have to edit your build to avoid triggering the
ktlintFormat
task on the code generated by KSP.
m
Ah, it try to reformat the code in my build folder where the classes are?
j
That's the issue yes! 😉
Hi @mudasar187, did you manage to fix the problem?
m
No 😞
j
Would you be willing to share your code? Or at least a reproducible example?