Hi. Is there any way to change default output fold...
# ksp
j
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
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
@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
>
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
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
You should not add the scrDir manually, it should be added by KSP.
m
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
You should not add the scrDir manually, it should be added by KSP.
Not in kmp yet
nod 1
m
(well this issue is closed... but I'm pretty sure the KMP setup requires some amount of manual configuration)
e
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
You have to manually specify the generated
srcDir
and also add a dependsOn to all Kotlin Compile.
c
Well, adding the processor to the common configuration shouldn’t require any manual setup imo.
e
Yes agreed 😅