运行Maven2 build时使用不同的Java源代码版本

SSa*_*mon 2 java maven-2

我试图使用通常的方式运行我的Maven构建:

mvn clean install
Run Code Online (Sandbox Code Playgroud)

我收到了一系列错误:

annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
Run Code Online (Sandbox Code Playgroud)

如何在执行构建时使用-source 5.我的JAVA_HOME指向JDK 1.6.

kay*_*ahr 6

将其添加到您的pom.xml:

<build>
  <plugins>
    <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>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

它也在Maven常见问题中记录.

有关更多信息,请查看Compiler Plugin文档.