Grails 4 upgrade - Error message unable to find a single main class
Asked Answered
S

2

9

I am currently upgrading from Grails 3.3.10 to Grails 4.0.0. When attempting to run my project I get the following error:

 Execution failed for task ':bootRun'.
 15:31:02.101 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Unable to find a single main class from the following candidates [com.torque.Application, com.base.torque.ExtendedReportsController, com.base.torque.utils.NaturalOrderComparator]

Whether I try to run the project in my IDE or my terminal, I get the same error.

I uninstalled and reinstalled grails 4.0.0 and I still get the error. Tried ./gradlew clean, rebuilding, killall -9 java and still get the error.

This was not an issue with previous Grails versions. No clue what is causing the issue with Grails 4 and no clue how to solve. Any insight towards a solution would be appreciated.

Sperrylite answered 19/8, 2019 at 19:55 Comment(7)
Do you have a main method in com.base.torque.utils.NaturalOrderComparator and com.base.torque.ExtendedReportsController?Osmund
It would be very strange to have a main method in a controller or a comparator, but the error message suggests that is the case. The answer I posted below describes how to make the error go away. If the error is happening and you don't have main methods in those classes, I think that would represent a bug. If that is the case, please file an issue at github.com/grails/grails-core/issues and we can investigate.Osmund
@JeffScottBrown there is a main method in com.base.torque.utils.NaturalOrderComparator but not in the com.base.torque.ExtendedReportsController.Sperrylite
It looks like Spring Boot is confused and thinks there is a main method in com.base.torque.ExtendedReportsController.Osmund
@JeffScottBrown - that worked. Thank you.Sperrylite
I had this in Grails 4. After I did grails clean the error was gone.Excide
@August, yeah, this works for me.Jacquline
O
15

If you have multiple classes which contain a main method, you can disambiguate with something like this in your build.gradle:

springBoot {
    mainClassName = 'com.torque.Application'
}
Osmund answered 19/8, 2019 at 20:40 Comment(3)
I saw lots of recommendations and suggestions, but only this worked for me.Dihybrid
This was happening to me pretty much anytime I edited application.groovy or changelog.groovy. I assumed it had something to do with those being groovy scripts instead of classes. I was using the "clean" option and then the next run would work. This modification worked great.Idalla
"I assumed it had something to do with those being groovy scripts instead of classes." - Makes sense. The issue is related to any classes that have a main method in them, and all Groovy scripts have a main method in them (even though you don't see it in the source code). Glad you got it worked out!Osmund
D
1

This solved it for me on Grails 5.2.2:

springBoot {
    mainClass = "com.mypackage.Application"
}
Dol answered 13/8, 2022 at 23:22 Comment(1)
I think the question is targeting Grails 4.0.0.Osmund

© 2022 - 2024 — McMap. All rights reserved.