Dilraj Singh
04/28/2022, 5:45 AMkotlin.sourceSets.main {
kotlin.srcDirs(
file("$buildDir/generated/ksp/"),
)
}
ksp {
arg("ignoreGenericArgs", "false")
}
these lines are added to my app-module gradle fileTing-Yuan Huang
04/28/2022, 7:28 AMfile("$buildDir/generated/ksp/")
includes generated sources from both release and debug. Can you try to remove it?Dilraj Singh
04/28/2022, 7:49 AMval symbols = resolver
.getSymbolsWithAnnotation("my_annotation")
.filterIsInstance<KSClassDeclaration>()
symbols.forEach {
val packageName = it.packageName.asString()
val file = codeGenerator.createNewFile(
dependencies = Dependencies(false, *resolver.getAllFiles().toList().toTypedArray()),
packageName = packageName,
fileName = it.simpleName.asString()
)
}
it.packageName.asString()
is evaluated to <http://debug.kotlin.my|debug.kotlin.my>_package_name
and <http://release.kotlin.my|release.kotlin.my>_package_name
Oliver.O
04/28/2022, 12:39 PMpackageName
assignment like this?
val packageName = it.packageName.asString().substringAfter('.')
Dilraj Singh
04/28/2022, 12:48 PMpackageName
in codeGenerator
, it is still prefixed with debug.kotlin
Oliver.O
04/28/2022, 12:55 PMksp
is treating debug
and release
like different source sets. In this case, maybe the example project mentioned in issue https://github.com/google/ksp/issues/965 could help you in restricting code generation to just debug
or release
, but not both.Dilraj Singh
04/28/2022, 12:57 PMcodeGenerator.generatedFile.first().toString().sourceSetBelow("ksp")
but getting it for my file containing the annotation is giving me the path of the file. Not sure how can we determine the source set from that.
/Users/dilrajsingh/Desktop/Code/safe-compose-args/app/src/main/java/com/compose/type_safe_args/safecomposeargs/NavigationGraph.kt
This is what I get for inputSourceSet
kotlin.sourceSets.main {
kotlin.srcDirs(
file("$buildDir/generated/ksp/"),
)
}
with
androidComponents.onVariants {variant ->
kotlin.sourceSets.findByName(variant.name)?.kotlin?.srcDirs(
file("$buildDir/generated/ksp/${variant.name}/kotlin")
)
}
worksJiaxiang
04/28/2022, 5:15 PMOliver.O
04/28/2022, 6:51 PMSymbolProcessor
for cases where generated code would differ by source set.Jiaxiang
04/28/2022, 10:10 PMbuild.gradle
easily (via ksp {}
extension, see KSP example project), and this way we can avoid having to introduce android variant specific logic (there could be other scenarios where you need to specify different source sets for different build task)Oliver.O
04/28/2022, 10:47 PMkotlin.srcDir("build/generated/ksp/...")
, plus
• add("ksp...", ...)
, plus
• wiring the KSP task dependencies between source sets dependsOn(kspKotlinMetadata)
as seen in my example project's Gradle build script.
I understood the documentation (KSP with Kotlin Multiplatform | Kotlin) to discourage using ksp()
in Kotlin Multiplatform projects. If I got this wrong, using ksp()
per source set would at least allow me to specify the output source set (although requiring additional build script boilerplate). What I'd still be missing is the input source set, as KSP (at least in my example) always processes files from multiple input source sets per invocation.