DEV Community

Jasper Aurelio Villas
Jasper Aurelio Villas

Posted on

⚔️ Spring Boot Maven Plugin vs Maven Compiler Plugin — What’s the Difference? When you're working on a Spring B

When you're working on a Spring Boot project with Maven, you’ve probably seen both spring-boot-maven-plugin and maven-compiler-plugin in the pom.xml. They sound similar, but they serve completely different purposes.

Let’s break down the difference and when to use each. 👇


🔧 spring-boot-maven-plugin
This plugin is Spring Boot-specific. It helps you package your application into an executable JAR (or WAR), making it easy to deploy and run.

✅ What it does:
Packages your app with an embedded server (like Tomcat)

  • Allows mvn spring-boot:run for quick local development
  • Bundles all dependencies into a single runnable JAR

🚫 What it doesn’t do:

  • It does not control the Java compiler version
  • It does not support annotation processors like Lombok

🧰 maven-compiler-plugin
This plugin controls how your Java code is compiled — including setting the Java version and handling annotation processing.

✅ What it does:

  • Sets source and target Java versions (e.g., Java 17)
  • Adds support for annotation processors like lombok
  • Essential for compiling clean, version-compatible code

🚫 What it doesn’t do:

  • It does not package your Spring Boot app
  • It does not include runtime dependencies or embedded servers

🧠 TL;DR — Use Them Together
Plugin Use it for...
maven-compiler-plugin Compiling your code with correct Java version and annotation processors
spring-boot-maven-plugin Packaging and running your Spring Boot application

Both are essential — just for different parts of the build lifecycle.

✍️ Sample Setup

xml

<build>
  <plugins>

    <!-- Compiler plugin for Java version & Lombok support -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.11.0</version>
      <configuration>
        <source>17</source>
        <target>17</target>
        <annotationProcessorPaths>
          <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>

    <!-- Spring Boot plugin for building the app -->
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

  </plugins>
</build>
Enter fullscreen mode Exit fullscreen mode

🎯 Tip: If you're seeing unexpected behavior in your Spring Boot build or annotation processing isn't working (like with Lombok), double-check that you're not misusing these plugins.

Hope this clears up the confusion! 🚀

Top comments (0)