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

Unresolved reference: functionWithoutArgs #1

Open
muoipt opened this issue Oct 7, 2021 · 2 comments
Open

Unresolved reference: functionWithoutArgs #1

muoipt opened this issue Oct 7, 2021 · 2 comments

Comments

@muoipt
Copy link

muoipt commented Oct 7, 2021

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.

Screenshot 2021-10-07 at 5 46 41 PM

Thanks

@Morfly
Copy link
Owner

Morfly commented Oct 7, 2021

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 clean in completed or start project directories (depending on which one you are using) and run the main function again?

  • If it does not help, I would suggest also removing all the content of the main function and run it with the empty body. After the successful build please restore its content (functionWithoutArgs and myAmazingFunction calls) and see if your IDE can recognize them. Also, please check the contents of a main-project/build/generated/ksp/main/kotlin directory. It should contain the generated file.

  • If none of the above works for you, please open the main-project/build.gradle.kts file 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.

@bfreuden
Copy link

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:
image

image

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants