Maven 2.0.2 compiler plugin

Could you tell me that it is mandatory to specify the maven-compiler-plugin parameters in my POM in the section:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> 

If so, why so, I understand what he is doing, but not sure why this is necessary? Is there no other way to call javac in maven?

+4
source share
2 answers

Could you tell me if it is mandatory to provide details of the maven-compiler-plugin?

Not. But he will use Java 1.3 or something from the Stone Age to compile.

If so, why so, I understand what he is doing, but not sure why this is necessary?

The answer is no. But here is the reason. You do not want to compile using Java 1.3 into your new code. You need all the new features in Java 5. Do you? :) So you have to add these extra lines to your already cluttered POM.

Is there any other way to call javac in maven?

Not. But mvn compile or any other command will work, even if you do not have this block. But compilation will fail if there are any advanced things in the source code that are in Java 5 but not in the previous version.


Change 1

How does it compile to 1.3 when I have JDK 5?

Well, it is possible to install this in the Java compiler. See here the Java compiler options: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html

It says that you can install source et al in an older version.

+7
source

The maven-compiler-plugin section is optional. Defaults apply if you do not include this section in your pom.xml.

The default compiler is javac and is used to compile Java sources. Also note that currently the default source setting is 1.5, and the default setting is 1.5, regardless of the JDK that you are running Maven with.

My personal preference is to have an explicit configuration for the reasons below.

  • I don’t think that relying on external defaults is a good idea, as they can change when the plugin version is changed.
  • It is unlikely that I want a new project to be compiled for Java 1.5
+4
source

All Articles