Bug Resolution: Unable to find main class

Bug Description

  • IDE: IntelliJ IDEA 2021.3
  • Language: Java
  • Error: Unable to find main class

I have created a multi-module Spring Boot project that will serve as a tool library for other projects to use. When building the multi-module Spring Boot project, the IDE prompts the following error: Unable to find main class.


Solution

The plugin that comes with SpringBoot requires the main method.

1
2
3
4
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

Because this is a utility project, there is no main method, so you need to make the following changes to the parent's pom.xml:

1
2
3
4
5
6
7
8
9
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>

In a multi-module Springboot project, the child modules' pom.xml will inherit the configuration in the parent's pom.xml.