I just announced the new Spring 5 modules in REST With Spring:


1. Overview

This quick tutorial introduces the compiler plugin, one of the core plugins of the Maven build tool.

For an overview of the other core plugins, refer to this article.

2. Plugin Goals

The compiler plugin is used to compile the source code of a Maven project. This plugin has two goals, which are already bound to specific phases of the default lifecycle:

  • compile compile main source files
  • testCompile compile test source files

Here’s the compiler plugin in the POM:


We can find the latest version of this plugin here.

3. Configuration

By default, the compiler plugin compiles source code compatible with Java 5, and the generated classes also work with Java 5 regardless of the JDK in use. We can modify these settings in the configuration element:

    <-- other customizations -->

For convenience, we can set the Java version as properties of the POM:


Sometimes we want to pass arguments to the javac compiler. This is where the compilerArgs parameter comes in handy.

For instance, we can specify the following configuration for the compiler to warn about unchecked operations:

    <!-- other configuration -->

When compiling this class:

public class Data {
    List<String> textList = new ArrayList();

    public void addText(String text) {

    public List getTextList() {
        return this.textList;

we’ll see an unchecked warning on the console:

[WARNING] ... Data.java:[7,29] unchecked conversion
  required: java.util.List<java.lang.String>
  found:    java.util.ArrayList

As both goals of the compiler plugin are automatically bound to phases in the Maven default lifecycle, we can execute these goals with the commands mvn compile and mvn test-compile.

4. Conclusion

In this article, we went over the compiler plugin and described how to use it.

The complete source code for this tutorial can be found over on GitHub.

Next »
Quick Guide to the Maven Install Plugin
« Previous
Maven Resources Plugin

I just announced the new Spring 5 modules in REST With Spring: