I'm working on upstreaming the KSP implementation ...
# ksp
z
I'm working on upstreaming the KSP implementation of moshi codegen here but running into what looks like a bug with processing. When I breakpoint it in the
JsonClassSymbolProcessorTest#disableProguardGeneration()
test, it runs successfully the first time and then is called a second time, upon which it throws an exception internally (in thread) that appears to originate from parsing the file generated by the first pass. I think it's a bug, but I don't really know what exactly to file as I'm not sure where it's going wrong. Doing a second round makes sense to me, but I don't understand why it fails in this particular test case (and two others, but the rest are fine). The test runs fine in the moshix repo with no changes, but falls over in this repo and suggests something is up with the build. Let me know if there's somewhere specific I should dig!
Copy code
e: [ksp] org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException: Descriptor wasn't found for declaration CLASS
	at org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:18)
	at org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:17)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.findClassDescriptor(LazyDeclarationResolver.kt:88)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.getClassDescriptor(LazyDeclarationResolver.kt:62)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.getMemberScopeDeclaredIn$frontend(LazyDeclarationResolver.kt:227)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitProperty(LazyDeclarationResolver.kt:181)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitProperty(LazyDeclarationResolver.kt:94)
	at org.jetbrains.kotlin.psi.KtProperty.accept(KtProperty.java:58)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:94)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:91)
	at org.jetbrains.kotlin.resolve.lazy.ResolveSession.resolveToDescriptor(ResolveSession.java:368)
	at com.google.devtools.ksp.processing.impl.ResolverImpl.resolveDeclaration(ResolverImpl.kt:424)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl$propertyDescriptor$2.invoke(KSPropertyDeclarationImpl.kt:43)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl$propertyDescriptor$2.invoke(KSPropertyDeclarationImpl.kt:42)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl.getPropertyDescriptor(KSPropertyDeclarationImpl.kt:42)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl.access$getPropertyDescriptor(KSPropertyDeclarationImpl.kt:34)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl$getter$2.invoke(KSPropertyDeclarationImpl.kt:68)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl$getter$2.invoke(KSPropertyDeclarationImpl.kt:65)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl.getGetter(KSPropertyDeclarationImpl.kt:65)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitPropertyDeclaration(ResolverImpl.kt:321)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitPropertyDeclaration(ResolverImpl.kt:281)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSPropertyDeclarationImpl.accept(KSPropertyDeclarationImpl.kt:103)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitClassDeclaration(ResolverImpl.kt:297)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitClassDeclaration(ResolverImpl.kt:281)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSClassDeclarationImpl.accept(KSClassDeclarationImpl.kt:119)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitFile(ResolverImpl.kt:291)
	at com.google.devtools.ksp.processing.impl.ResolverImpl$getSymbolsWithAnnotation$visitor$1.visitFile(ResolverImpl.kt:281)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSFileImpl.accept(KSFileImpl.kt:61)
	at com.google.devtools.ksp.processing.impl.ResolverImpl.getSymbolsWithAnnotation(ResolverImpl.kt:339)
	at com.google.devtools.ksp.processing.Resolver$DefaultImpls.getSymbolsWithAnnotation$default(Resolver.kt:47)
	at com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessor.process(JsonClassSymbolProcessorProvider.kt:109)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$4$1.invoke(KotlinSymbolProcessingExtension.kt:185)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$4$1.invoke(KotlinSymbolProcessingExtension.kt:183)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:282)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:183)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:120)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:86)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:252)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:243)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:243)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.repeatAnalysisIfNeeded(KotlinToJVMBytecodeCompiler.kt:213)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:90)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:56)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at com.tschuchort.compiletesting.AbstractKotlinCompilation.compileKotlin(AbstractKotlinCompilation.kt:184)
	at com.tschuchort.compiletesting.KotlinCompilation.compileJvmKotlin(KotlinCompilation.kt:469)
	at com.tschuchort.compiletesting.KotlinCompilation.compile(KotlinCompilation.kt:645)
	at com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorTest.disableProguardGeneration(JsonClassSymbolProcessorTest.kt:394)
just went ahead and filed here https://github.com/google/ksp/issues/621. Going to ignore the three failing tests for now and link this, but easy to repro if you remove the
@Ignore
j
it does appears to be non-issue on linux, let me try on mac.
👍 1
u
Didn't the post say Moshi already supports KSP?
Copy code
Using Moshi or Room with KSP

If you’re using Moshi or Room in your project, you can already try out KSP by making a quick fix to your module’s build file. For example, to use the KSP version of Room in a Gradle module you can simply replace the KAPT plugin with KSP and swap out the KSP dependency:
z
If you read the PR, it's upstreaming it from MoshiX, which is where the implementation has been until KSP is stable
u
I see. Thanks for clarifying.