Moving a Springboot’s project pom.xml to own parent

I’m working on a multi-module project that started out as a bunch of independent projects with little or no interdependencies. Each module inherited from spring-boot-starter-parent but as soon as the project started to grew in complexity, more proper dependency management became a necessity.

I moved moved all the common and Spring related dependencies to my parent pom.xml and opted for using Springboot without the starter parent POM. Basically I had to replace the parent definition for each module and add spring-boot-dependencies in the dependency-management section of the parent pom.xml

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.5.6</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

That is sufficient to bring in all the dependencies and dependencyManagement into each project, beside that all the rest should continue to work as usual. Infact everyhing seemed to work as expected, at least in the development/test phases

The problem

Problems arose when I tried to package my application for the deployment. I built the application as usal and tried to launch the newly built jar but ll I could get was an error message:

no main manifest attribute, in project-1.0.0-SNAPSHOT.jar

Frankly I didn’t realize how much my build process was dependent on Springboot’s automagic configuration, a lot of things were inherited from spring-boot-starter parent, not only the dependencies stuff and now basically all the plugin configurations were missing.

In particular, the repackage goal of springboot-maven-plugin wasn’t executed anymore and the .jar was now only 7.5Mb and lacking the manifest file.

Solution

In my case, to get things working again I had to manually add the following snippet to the build configuration of my pom.xml of my executable .jar:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<version>${springboot.version}</version>
	<executions>
	    <execution>
		<goals>
		    <goal>repackage</goal>
		</goals>
	    </execution>
	</executions>
</plugin>

Conclusion

A lot of other plugins are configured under the hood when you inherit from springboot-starter-parent, so if the build process start to behave unexpectedly after a changing the parent pom.xml watch out for these plugins in spring-boot-starter-parent’s pom.xml:

  • kotlin-maven-plugin
  • maven-compiler-plugin
  • maven-failsafe-plugin
  • maven-jar-plugin
  • maven-war-plugin
  • exec-maven-plugin
  • maven-resources-plugin
  • git-commit-id-plugin
  • spring-boot-maven-plugin
  • maven-shade-plugin
  • spring-boot-maven-plugin
  • lifecycle-mapping
  • flatten-maven-plugin
  • maven-checkstyle-plugin

Knew it (sapevatelo).