Thursday, May 10, 2012

annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)

Maven 2 fails to compile some projects where post java 1.3 features are used, like annotations below:
annotations are not supported in -source 1.3 
(use -source 5 or higher to enable annotations)
This is easily addressable when you own the pom files. For example to ensure java 1.6 code will compile you will use:
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
However sometimes you are strugling with projects built from maven 3 in which case the default is not 1.3 and so the original author has not added the above bits in the project pom(s). Here is then what you have to do to compile such projects from maven 2:
$ mvn clean install -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6

No comments:

Followers