No value specified for property 'mainClassName'

I am trying to create a project with

apply plugin: 'spring-boot'

      

But it throws an exception at startScripts stage

: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 don't need the main class for this module. How do I solve this?

+3


source to share


2 answers


There's an open ticket about this issue on the Spring-Boot GitHub: https://github.com/spring-projects/spring-boot/issues/2679 . There are several things you can do as per the discussion:

  • Remove the plugin spring-boot

    from the section buildscript

    . This will remove the custom Gradle tasks from the build stream.
  • Assign to mainClassName

    some random string. This isn't great, but since it doesn't work, you probably don't care about the main class.
  • There are some more cumbersome ways to fix this problem if you want to try them.


Hope it helps.

+2


source


You need a method main

that calls SpringApplication.run(...)

. Like this:

public static void main(String[] args) throws Exception {
  SpringApplication.run(Example.class, args);
}

      

In the Getting Started Guide , this is a paragraph about the method main

:

The last part of our application is the main method. This is just a standard method following the Java convention for the entry point application. Our main method delegates Spring Boots to the SpringApplication class by calling run. SpringApplication will load our application by starting Spring, which in turn will start the automatically configured Tomcat web server. We need to pass Example.class as an argument to the run method to tell SpringApplication which is the main Spring bean. The args array is also passed to expose any command line arguments.



I recommend creating a class Application

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 first .

+1


source







All Articles