https://kotlinlang.org logo
#ksp
Title
# ksp
j

Jithin Murali

03/29/2024, 9:44 AM
Hi. Is there any way to change default output folder path for KSP generated codes. Currently the generated files (using ksp annotation) are stored in folder
build/generated/ksp/variantname/kotlin
Can i able to change this path to a custom path bcoz i had problem with the variant naming.
m

mbonnin

03/29/2024, 9:48 AM
What is the problem you're having? I'm more and more convinced Gradle tasks output locations are implementation details and should not matter
1
j

Jithin Murali

03/29/2024, 10:02 AM
@mbonnin In our app , we have too many number of variants. for ex - debug, staging, release. If i generated code with currently having debug as active build variant, generated files are stored into
build/generated/ksp/debug/kotlin -
this folder Now if i change my variant to another (for ex - release) - newly generated files will store in to
build/generated/ksp/release/kotlin
1st issue is , I need to mention both directory as source directory in this case. Like this.
applicationVariants.all *{* variant *->*
sourceSets *{*
println("$variant.name")
main *{*
kotlin.srcDirs += ["$buildDir/generated/ksp/$<http://variant.name/kotlin%22|variant.name/kotlin">]
}
}
}
2nd issue : Some build exceptions occurred if both generated folders are available in the build at the same time. If i clean the build and run , it will create only one folder and it runs fine. But otherwise it cause some task failures.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptCnStagingKotlin'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:147)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:145)
m

mbonnin

03/29/2024, 10:05 AM
>
kaptCnStagingKotlin
Looks like there another issue in your build. I don't think changing the default KSP output dir here is going to be the solution
j

Jithin Murali

03/29/2024, 10:13 AM
My idea is to make a common directory - to store generated files. Like
build/generated/ksp/commonDir/kotlin
If thats the case, there will be no duplicates.
kaptCnStagingKotlin
- When i cleaned the build and run this task it works fine.( Only cnStaging variant generated folders are there) --> For example if i already have cnRelease variant - generated files and run this task, it throws this exception.
h

hfhbd

03/29/2024, 10:15 AM
You should not add the scrDir manually, it should be added by KSP.
m

mbonnin

03/29/2024, 10:16 AM
Agreed, that's the perfect world where KSP does all the wiring for you
Last time I checked it was a bit of a work in progress with KMP though, not sure what the status is with Android variants?
c

Cherrio LLC

03/29/2024, 2:44 PM
You should not add the scrDir manually, it should be added by KSP.
Not in kmp yet
nod 1
m

mbonnin

03/29/2024, 2:46 PM
(well this issue is closed... but I'm pretty sure the KMP setup requires some amount of manual configuration)
e

eygraber

03/29/2024, 3:45 PM
I have to double check but I don't think I've done any manual configuration with KMP in a while (unless I hid it in a convention plugin and forgot about it 😬)
😄 1
c

Cherrio LLC

03/29/2024, 3:48 PM
You have to manually specify the generated
srcDir
and also add a dependsOn to all Kotlin Compile.
c

Cherrio LLC

03/29/2024, 4:17 PM
Well, adding the processor to the common configuration shouldn’t require any manual setup imo.
e

eygraber

03/29/2024, 4:25 PM
Yes agreed 😅
12 Views