Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin 2, ksp 1 and ktorfit clashing in multimodule project #634

Open
lepicekmichal opened this issue Aug 17, 2024 · 5 comments
Open

kotlin 2, ksp 1 and ktorfit clashing in multimodule project #634

lepicekmichal opened this issue Aug 17, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@lepicekmichal
Copy link

Ktorfit version

2.0.1

What happened and how can we reproduce this issue?

Upgrading from kotlin 1.9.24 to kotlin 2.0.x and ktorfit 2.0.1 in my multimodule project has been giving error messages while trying to compile.

I have ktorfit interface inside module A, which sees on module B where class TeamResponse is located.

package com.example.abc.team

import com.example.abc.api.team.TeamResponse
import com.example.abc.api.team.TeamRequest

interface NamedTeamService {

    @GET("named-players-teams")
    suspend fun fetchTeams(): List<TeamResponse>

    @POST("named-players-teams")
    @Headers("Content-Type: application/json")
    suspend fun addTeam(
        @Body team: TeamRequest,
    ): TeamResponse

    @DELETE("named-players-teams/{id}")
    suspend fun deleteTeam(@Path("id") teamId: Int)
}

And it will always give this error:

[ksp] java.lang.IllegalArgumentException: Error type '<ERROR TYPE: TeamResponse>' is not resolvable in the current round of processing.
	at com.squareup.kotlinpoet.ksp.KsTypesKt.requireNotErrorType(KsTypes.kt:40)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:71)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:202)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:177)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:74)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:65)
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName$default(KsTypes.kt:63)
	at de.jensklingenberg.ktorfit.poetspec.UtilsKt.findTypeName(Utils.kt:22)
	at de.jensklingenberg.ktorfit.poetspec.FunctionSpecKt.toFunSpec(FunctionSpec.kt:20)
	at de.jensklingenberg.ktorfit.poetspec.FileSpecKt.getImplClassSpec(FileSpec.kt:101)
	at de.jensklingenberg.ktorfit.generator.ClassGeneratorKt.generateImplClass(ClassGenerator.kt:24)
	at de.jensklingenberg.ktorfit.KtorfitProcessor.process(KtorfitProcessor.kt:50)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:310)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:308)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:414)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:308)
	at org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory$Companion.analyzeFiles(CommonResolverForModuleFactory.kt:204)
	at org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory$Companion.analyzeFiles$default(CommonResolverForModuleFactory.kt:143)
	at org.jetbrains.kotlin.cli.metadata.CommonAnalysisKt.runCommonAnalysisIteration$lambda$1(CommonAnalysis.kt:72)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
	at org.jetbrains.kotlin.cli.metadata.CommonAnalysisKt.runCommonAnalysisIteration(CommonAnalysis.kt:71)
	at org.jetbrains.kotlin.cli.metadata.CommonAnalysisKt.runCommonAnalysisForSerialization(CommonAnalysis.kt:38)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer.analyze(K2MetadataKlibSerializer.kt:45)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataKlibSerializer.analyze(K2MetadataKlibSerializer.kt:40)
	at org.jetbrains.kotlin.cli.metadata.AbstractMetadataSerializer.analyzeAndSerialize(AbstractMetadataSerializer.kt:34)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:134)
	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:48)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1556)
	at jdk.internal.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

If I comment out the TeamResponse, TeamRequest will be the next error.
If I turn on ksp2, then the nullability issue of ksp2 is first to be served.

What did you expect to happen?

no error

Is there anything else we need to know about?

No response

@lepicekmichal lepicekmichal added the bug Something isn't working label Aug 17, 2024
@lepicekmichal
Copy link
Author

I arrived to the same problem with your example multiplatform project. All that was needed is create basic module with the Person data class and connect a dependency to the module from shared module.
Same exception.

@Foso
Copy link
Owner

Foso commented Aug 25, 2024

Hi, I just updated the example project to multi module and i don't have any issues https://github.com/Foso/Ktorfit/tree/master/example/MultiplatformExample

@lepicekmichal
Copy link
Author

lepicekmichal commented Aug 26, 2024

This is fascinating problem. If I take your example project, I can build it. However, if I remove all lines regarding ios in build.grade.kts, I will arrive to the bug.
jvm+android is not enough.
If I add any of the ios (x64, macos, doesnt matter), build is working again.

**IMPORTANT EDIT: **You must do build>clean after/before syncing for gradle changes. Otherwise, the problem won't show up, because it takes a cached successful build or something.

@lepicekmichal
Copy link
Author

js target is also making it work. I honestly guess it is a KSP problem but maybe you could find out exactly what and work your way around it?

@Foso
Copy link
Owner

Foso commented Aug 26, 2024

okay, thank you for trying it. Maybe i find a solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants