#AskMe

When do we use maven-compiler-plugin ?

Overview

The Compiler Plugin is used to compile the sources of your project.

Setup

Place following the maven pom structure, please add following lines to plugins block:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <configuration>
      <source>1.6</source>
      <target>1.6</target>
      <encoding>UTF-8</encoding>				  
    </configuration>
</plugin>

The version, you need to define according to the maven2 version you installed. All versions, you can find from here.

Do we really need it and When?

By default, if you don’t want to modify the way maven will compile your project, you do not need to put this plugin, only when:

Compile Using A Different JDK

Compile Using -source and -target javac Options

Compile Using Memory Allocation Enhancement

Pass Compiler Arguments

Most of the case above, you will be likely to use as above configuration sample, define encoding, source and target. More information, you can find from here.

Have I missed something? Please share your answer in comment below?