Categories
Java

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

  • You want to compile (javac) from a specific JDK folder (D:/java/jdk1.5.x/bin)

Compile Using -source and -target javac Options

  • You want to specify source and target of the compiler version (as above example)

Compile Using Memory Allocation Enhancement

  • Allocate your memory to use for compilation, mostly when you need to limit or force more memory to use

Pass Compiler Arguments

  • Sometimes, you need to pass other compiler arguments that are not handled by the Compiler Plugin (rt.jar)

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?

 

One reply on “When do we use maven-compiler-plugin ?”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.