I am trying to build a project with
apply plugin: 'spring-boot'
But it throws an exception at the step startScripts
:common:compileJava UP-TO-DATE :common:processResources UP-TO-DATE :common:classes UP-TO-DATE :common:jar UP-TO-DATE :common:findMainClass :common:startScripts FAILED FAILURE: Build failed with an exception. * What went wrong: A problem was found with the configuration of task ':common:startScripts'. > No value has been specified for property 'mainClassName'.
But I really do not need a main Class for this module. How should I settle this?
There's an open ticket about this issue on Spring-Boot's GitHub: https://github.com/spring-projects/spring-boot/issues/2679. There are couple things you can do according to discussion:
- Remove
spring-boot
plugin from buildscript
section. This will remove special Gradle tasks from build flow. - Assign
mainClassName
to some random string. It's not pretty but as far as this is not runnable app you probably don't care about main class. - There are some more bulky ways to solve this listed by the link if you want to try them.
Hope this helps.
You need a main
method which calls SpringApplication.run(...)
. Like this:
public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); }
In the Gettings started guide is a paragraph about the main
method:
The final part of our application is the main method. This is just a standard method that follows the Java convention for an application entry point. Our main method delegates to Spring Boot’s SpringApplication class by calling run. SpringApplication will bootstrap our application, starting Spring which will in turn start the auto-configured Tomcat web server. We need to pass Example.class as an argument to the run method to tell SpringApplication which is the primary Spring component. The args array is also passed through to expose any command-line arguments.
I recommend to create a Application
class where it all starts:
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
But, perhaps you should start with the Quick start guide at first.