Maven Install: “Annotations are not supported in -source 1.3”

前端 未结 5 1980
野趣味
野趣味 2020-12-11 01:40

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\\testru         


        
相关标签:
5条回答
  • 2020-12-11 02:08

    A shorter version:

    <project>
        <properties>
            <maven.compiler.source>1.5</maven.compiler.source>
            <maven.compiler.target>1.5</maven.compiler.target>
        </properties>
    ....
    
    0 讨论(0)
  • 2020-12-11 02:09

    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/

    0 讨论(0)
  • 2020-12-11 02:09

    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>
    
    0 讨论(0)
  • 2020-12-11 02:13

    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.

    0 讨论(0)
  • 2020-12-11 02:22

    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.

    0 讨论(0)
提交回复
热议问题