Maven Compiler Plugin

The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. The default source setting is 1.3 and the default target setting is 1.1, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.

This Compiler Plugin is the Maven 2 version of Maven 1.x's Java Plugin.

NOTE: To know more about the Java JDK 1.4 javac, please see: http://java.sun.com/j2se/1.4.2/docs/tooldocs/tools.html#basic.

Goals Overview

The Compiler Plugin has two goals. Both are already bound to their proper phases within the Maven Lifecycle and are therefore, automatically executed during their respective phases.

  • compiler:compile is bound to the compile phase and is used to compile the main source files.
  • compiler:testCompile is bound to the test-compile phase and is used to compile the test source files.

Usage

Instructions on how to use the Compiler Plugin can be found here.

Examples

To provide you with better understanding on some usages of the Compiler Plugin, you can take a look into the following examples: