Friday, March 23, 2012

Maven Compiler Version from Command Line

Maven 2 default compiler version was 1.3, then for latest releases the default is 1.5. Maven 3 allows to set the compiler just in the parent pom.

Here is how to specify from command line the maven property that will set which compiler to use
$ mvn clean install -Dmaven.compiler.source=1.6
This comes in handy especially to avoid errors like:
annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override public void initialize() {
Of course you can always edit the pom files as below but that would probably not be a good practice when you are not the owner of the project and the team maintaining it is using a different maven/compiler version than yours.

1 comment:

Alex Averbuch said...

Thanks, great tip!
Saved me from a bunch of errors like:

static import declarations are not supported in -source 1.3