maven :(使用-source 5或更高版本来启用静态导入声明)

maven :(使用-source 5或更高版本来启用静态导入声明)

问题描述:

如何使用源5?
我试过

How can I use source 5? I tried

mvn -source 5 test

但它不起作用: - )

but it didn't work :-)

当我用javac编译文件时,一切正常。

When I compile the file by javac, everything works.

您需要配置 maven-compiler-plugin

You need to configure the maven-compiler-plugin:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
</project>

编辑:更改示例以使用最新版本的插件。

Changed example to use latest version of the plugin.