Sangeet Narayan
02/15/2021, 3:38 AMgradle run
but it gave me this error:
Error: Could not find or load main class com.demo.AppKt
Caused by: java.lang.ClassNotFoundException: com.demo.AppKt
Here’s the declaration of main class in my gradle file configuration (will be happy to share the whole file as well):
application {
mainClassName = "com.demo.AppKt"
}
And here’s my project structure:
demo(root folder)
-- application(module 1)
-- src/main/kotlin
--com.demo
-- App.kt
-- build.gradle.kt
-- login (module 2)
-- build.gradle.kt
-- (other build, IDE and gradle folders)
Can anyone tell what error am I doing?Vampire
02/15/2021, 8:46 AMgradle
but the Gradle wrapper, if you are using mainClassName
instead of mainClass
you are probably using an old Gradle version, the build scripts must end in .gradle.kts
, not .gradle.kt
Sangeet Narayan
02/15/2021, 8:51 AMbuild.gradle.kts
file not be as specified above.Sangeet Narayan
02/15/2021, 8:53 AMVampire
02/15/2021, 8:58 AMAppKt
class anywhere, just as the error says. Btw. setting the main class attribute on the jar is not going to help.Sangeet Narayan
02/15/2021, 9:03 AMSangeet Narayan
02/15/2021, 9:05 AMcom.demo.DemoApplicationKt
right?
Doesn’t work with that too.Sangeet Narayan
02/15/2021, 9:06 AM./gradlew run
inside the application module, it worksSangeet Narayan
02/15/2021, 9:07 AMVampire
02/15/2021, 11:29 AMapplication
plugin there an had there main class set to AppKt
.
You have the application
plugin applied to your root project and your application
project.
So what happens if you do gradlew run
is, that all run
task in all project are executed.
It starts with :run
(the on in the root project) and that fails due to class not found and then the build fails.
If you would have done gradlew --continue run
, then after :run
failed it would have started :application:run
as it does not depend on the failed task.
So if you want to start the run
task in the application
project specifically, use gradlew application:run
, or actually gradlew a:r
would be enough in your case.
If you remove the application
plugin from the root project, just doing gradlew run
is also fine again as then only the application
project has a run
task.
Or you can of course also apply the application
plugin to the root project if you there depend on your application
project and use the correct class name.Sangeet Narayan
02/15/2021, 3:44 PMVampire
02/15/2021, 3:45 PMVampire
02/15/2021, 3:45 PMVampire
02/15/2021, 3:45 PMVampire
02/15/2021, 3:46 PMSangeet Narayan
02/15/2021, 3:48 PMSangeet Narayan
02/15/2021, 3:48 PM