0Pricing
Java Academy · Lesson

Maven Plugins and Goals

Customize the build.

Maven Plugins and Goals is a free Java Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Maven Plugins and Goals

Maven itself does almost nothing — all real work is done by plugins. A plugin contributes goals, and goals are bound to lifecycle phases. This lesson shows how plugins customize a build.

Plugins vs Goals

A plugin is a packaged collection of related capabilities. A goal is one specific task within a plugin. For example the Compiler Plugin provides the compile and testCompile goals.

Goal Coordinates

You can invoke a goal directly as plugin:goal. For instance mvn compiler:compile or mvn surefire:test. Normally goals run automatically because they are bound to phases.

Phase Bindings

The default packaging type pre-binds standard plugins to phases. For a jar project, the Compiler Plugin's compile goal binds to the compile phase, and the Surefire Plugin's test goal binds to test — which is why mvn test just works.

Configuring the Compiler

You configure a plugin inside <build><plugins>. Here we set the Java release level so the compiler targets a specific version.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.13.0</version>
      <configuration>
        <release>21</release>
      </configuration>
    </plugin>
  </plugins>
</build>

The Surefire Plugin

Surefire runs unit tests during the test phase. You can configure which tests to include, parallelism, and JVM arguments. Its sibling, Failsafe, runs integration tests in the verify phase.

Binding an Extra Execution

An <execution> block binds a goal to a phase explicitly, optionally with its own configuration. This is how you attach extra work, like generating code before compilation.

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>print-banner</id>
      <phase>generate-sources</phase>
      <goals><goal>run</goal></goals>
    </execution>
  </executions>
</plugin>

Building a Fat JAR

The default JAR does not include dependencies. The Shade plugin (or Assembly plugin) bundles everything into one runnable uber-jar, binding its goal to the package phase.

The Exec Plugin

The Exec plugin lets you run your application from Maven with mvn exec:java, specifying the main class. Handy for quick runs without packaging.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <configuration>
    <mainClass>com.example.App</mainClass>
  </configuration>
</plugin>

Plugin Management

In a multi-module build, <pluginManagement> in the parent POM pins plugin versions and shared config. Child modules then reference the plugin without repeating the version, keeping builds consistent.

Discovering Configuration

Use mvn help:describe -Dplugin=compiler to list a plugin's goals and parameters. This is the fastest way to learn what knobs a plugin exposes without leaving the terminal.

Quick Check

Test your understanding of plugins and goals.

Recap

You learned how Maven plugins work:

  • All real build work is done by plugins, which contribute goals.
  • Goals are bound to lifecycle phases, so standard phases just work.
  • Configure plugins in <build><plugins>; add executions for extra bindings.
  • Shade/Assembly build fat JARs; Exec runs the app; Surefire/Failsafe run tests.
  • mvn help:describe reveals a plugin's goals and parameters.

Frequently asked questions

Is the “Maven Plugins and Goals” lesson free?

Yes — the full text of “Maven Plugins and Goals” is free to read here on the web, and the Java Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Maven Plugins and Goals”?

Customize the build. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Maven Plugins and Goals” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Maven Project Structure
  2. Maven Plugins and Goals
  3. Gradle Basics
  4. Choosing a Build Tool
← Back to Java Academy