James Raitsev
James Raitsev

Reputation: 96421

Maven Install: "Annotations are not supported in -source 1.3"

When running mvn install on my project, i see it fail due to the following errors:

C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Test

C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Test

My Maven dependency includes jUnit 4.8, however and has no reference to 1.3 anything.

What would cause these errors? Please advise

Upvotes: 14

Views: 9911

Answers (5)

Bu default, the maven tries to compile using Java 1.3 version. I hope most of them hit this error because of missing to tell maven that "Hey Maven, Dont use 1.3 and use "whatever_version_I_give"

This can be mentioned in pom.xml as below :

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

In my above example, I have used 1.7. Please replace with whatever version you wish to.

Upvotes: 1

ajaysoni98292
ajaysoni98292

Reputation: 11

Add this in your pom

<build>
       <pluginManagement>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.0</version>
                      <configuration>
                          <!-- put your configurations here -->
                      </configuration>
               </plugin> 
          </plugins>
       </pluginManagement>
    </build>

Upvotes: 0

rzymek
rzymek

Reputation: 9281

A shorter version:

<project>
    <properties>
        <maven.compiler.source>1.5</maven.compiler.source>
        <maven.compiler.target>1.5</maven.compiler.target>
    </properties>
....

Upvotes: 4

You are most likely using OpenJDK where the source level is 1.3 when not explicitly set - as opposed to Oracle JDK where the source level is 1.5.

Since most modern Java projects target newer code than Java 5 you most likely need to set this anyway.

Also note that if you need a lower target than source (e.g. for compiling with Java 6 but deploying to Java 5) you can do this by using the Eclipse compiler instead of Javac.

Upvotes: 2

gregwhitaker
gregwhitaker

Reputation: 13410

You need to specify the source version of your maven project through the use of the maven-compiler-plugin. Add the following to your pom build element and set the appropriate java source and target levels.

<build>
     <defaultGoal>install</defaultGoal>
     <plugins>
          <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
               </configuration>
          </plugin>
      </plugins>
</build>

http://maven.apache.org/plugins/maven-compiler-plugin/

Upvotes: 24

Related Questions