Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Java builds (Maven, Gradle, JAR, WAR)

What are Maven plugins? Name some you've used.

IntermediateConceptJava builds (Maven, Gradle, JAR, WAR)
Answer

Short answer

Maven itself does very little — plugins do the actual work. Every lifecycle phase is bound to plugin goals: the compiler plugin compiles, Surefire runs tests, the JAR plugin packages. You add extra plugins for things like building a Spring Boot fat JAR, code coverage or Docker images.

Common plugins

Plugin What it does Phase
maven-compiler-plugin Compiles Java source compile
maven-surefire-plugin Runs unit tests test
maven-failsafe-plugin Runs integration tests (*IT.java) integration-test / verify
maven-jar-plugin / maven-war-plugin Packages JAR / WAR package
spring-boot-maven-plugin Repackages into an executable fat JAR package
jacoco-maven-plugin Code coverage reports (for SonarQube) test / verify
sonar-maven-plugin mvn sonar:sonar analysis —
jib-maven-plugin Builds container images without Docker package

Example

<build>
  <plugins>
    <plugin>
      <groupId>org.jacoco</groupId>
      <artifactId>jacoco-maven-plugin</artifactId>
      <version>0.8.12</version>
      <executions>
        <execution><goals><goal>prepare-agent</goal></goals></execution>
        <execution><id>report</id><phase>verify</phase><goals><goal>report</goal></goals></execution>
      </executions>
    </plugin>
  </plugins>
</build>

You can also run a plugin goal directly: mvn dependency:tree, mvn versions:display-dependency-updates, mvn sonar:sonar.

What to say in the interview

"Maven is plugin-based — phases are just hooks where plugin goals run. In our pipelines we use Surefire for tests, JaCoCo for coverage that feeds SonarQube, the Spring Boot plugin for the executable JAR, and sometimes Jib to build images without a Docker daemon."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

More on Java builds (Maven, Gradle, JAR, WAR)