ksp-sample
ksp-sample copied to clipboard
Unresolved reference: functionWithoutArgs
Hi, I tried to run main() function in Main.kt class but there is error "Unresolved reference: functionWithoutArgs". So I can not run. Pls help with this.
Thanks
Hi,
Please let me know if you're building the completed project or do you use a start directory by following the blog post?
I've seen this issue once or twice on one of the beta versions of KSP. To me, it looked like a bug with KSP but the tips below helped me to fix it.
-
Could you please try to run a
./gradlew cleanincompletedorstartproject directories (depending on which one you are using) and run themainfunction again? -
If it does not help, I would suggest also removing all the content of the
mainfunction and run it with the empty body. After the successful build please restore its content (functionWithoutArgsandmyAmazingFunctioncalls) and see if your IDE can recognize them. Also, please check the contents of amain-project/build/generated/ksp/main/kotlindirectory. It should contain the generated file. -
If none of the above works for you, please open the
main-project/build.gradle.ktsfile and add the following lines to it:
plugins {
...<all other plugins>
application
}
application {
mainClass.set("com.morfly.MainKt")
}
...<all other content>
The application plugin will allow you to run the project from the command line. Try to run ./gradlew main-project:run command and check if it works.
Please, let me know if it helps.
Hi,
Thank you for sharing this example!
I'm having the same issue: screenshot is exactly the same as the OP's (on the completed project).
Please note that everything is working properly when running gradle from the command line:
bruno@hearne:~/dev/github/ksp-sample/completed$ gradle main-project:run
The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':annotations', ':main-project'
> Task :main-project:run
Hello from functionWithoutArgs
Hello from myAmazingFunction
Once gradle has been run from the command-line, IntelliJ is happy. But run...
gradle clean
... and the issue is back.
It seems somehow that IntelliJ is unable to invoke ksp code generation, although it is configured to use gradle:


Do you know if it is expected to be working? Thank you!