-
|
Is it possible to fail build when KSP is not configured but |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Yes, it's possible to fail the build if KSP (Kotlin Symbol Processing) is not properly configured but the @JsonClass(generateAdapter = true) annotation from Moshi is used. Currently, the default behavior in this scenario is that the adapter is not generated, and there is no explicit failure of the build, which can lead to runtime errors due to missing adapters. To force the build to fail when this happens, you can take the following approach:
tasks.register("checkKspConfigured") { You can then add a dependency to your build task to ensure that this check runs during the build process: tasks.named("compileKotlin").configure {
Another approach is to enforce this rule using a static analysis tool or a custom lint rule. This can ensure that any use of @JsonClass(generateAdapter = true) without KSP or generated adapters causes a warning or failure at build time. You could also create a custom annotation processor or lint rule to detect the use of @JsonClass without the necessary configuration and fail the build.
You can create a Kotlin compiler plugin or use a pre-existing one to analyze the source code for the presence of the @JsonClass(generateAdapter = true) annotation without proper KSP configuration, then halt the build process. |
Beta Was this translation helpful? Give feedback.
Yes, it's possible to fail the build if KSP (Kotlin Symbol Processing) is not properly configured but the @JsonClass(generateAdapter = true) annotation from Moshi is used. Currently, the default behavior in this scenario is that the adapter is not generated, and there is no explicit failure of the build, which can lead to runtime errors due to missing adapters.
To force the build to fail when this happens, you can take the following approach:
You can add a custom Gradle task to check whether KSP is correctly configured. This task could verify if the necessary KSP dependencies are included in the build or check if generated adapters exist after…