Maven安装:“ - 1.3”中不支持注释

时间:2011-06-28 21:48:05

标签: maven junit annotations

在我的项目上运行mvn install时,由于以下错误,我看到它失败了:

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

我的Maven依赖包括jUnit 4.8,但并没有提及1.3任何内容。

什么会导致这些错误?请指教

5 个答案:

答案 0 :(得分:24)

您需要通过使用maven-compiler-plugin指定maven项目的源版本。将以下内容添加到pom构建元素中,并设置适当的java源和目标级别。

<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/

答案 1 :(得分:4)

较短的版本:

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

答案 2 :(得分:2)

您最有可能使用OpenJDK,其中未明确设置源级别为1.3 - 而不是源级别为1.5的Oracle JDK。

由于大多数现代Java项目的目标都是比Java 5更新的代码,因此您最有可能需要设置它。

另请注意,如果您需要比源更低的目标(例如,使用Java 6进行编译但部署到Java 5),则可以使用Eclipse编译器而不是Javac来执行此操作。

答案 3 :(得分:1)

Bu默认情况下,maven尝试使用Java 1.3版本进行编译。我希望他们中的大多数都会遇到这个错误,因为他告诉maven&#34; Hey Maven,不要使用 1.3 并使用&#34; whatever_version_I_give&#34; < / p>

这可以在pom.xml中提到如下:

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

在上面的示例中,我使用了 1.7 。请替换为您想要的任何版本。

答案 4 :(得分:0)

在你的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>
相关问题