源值 1.5 的错误已过时,将在未来版本中删除 [英] Error of source value 1.5 is obsolete and will be removed in a future release

查看:72
本文介绍了源值 1.5 的错误已过时,将在未来版本中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 scala-maven-plugin 来编译一个包含 Scala 和 Java 代码的项目.我已经将源和目标设置为 1.7,但不知道为什么 maven 仍然使用 1.5.

I use scala-maven-plugin to compile a project with both scala and java code. I already set the source and target to 1.7, but not sure why maven still use 1.5.

这是我在 pom.xml 中的插件

Here's my plugin in pom.xml

<plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.2.2</version>
        <executions>
          <execution>
            <id>eclipse-add-source</id>
            <goals>
              <goal>add-source</goal>
            </goals>
          </execution>
          <execution>
            <id>scala-compile-first</id>
            <phase>process-resources</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>scala-test-compile-first</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
          <execution>
            <id>attach-scaladocs</id>
            <phase>verify</phase>
            <goals>
              <goal>doc-jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <recompileMode>incremental</recompileMode>
          <useZincServer>true</useZincServer>
          <args>
            <arg>-unchecked</arg>
            <arg>-deprecation</arg>
            <arg>-feature</arg>
          </args>
          <jvmArgs>
            <jvmArg>-Xms1024m</jvmArg>
            <jvmArg>-Xmx1024m</jvmArg>
            <jvmArg>-XX:PermSize=${PermGen}</jvmArg>
            <jvmArg>-XX:MaxPermSize=${MaxPermGen}</jvmArg>
          </jvmArgs>
          <javacArgs>
            <javacArg>-source</javacArg>
            <javacArg>1.7</javacArg>
            <javacArg>-target</javacArg>
            <javacArg>1.7</javacArg>
            <javacArg>-Xlint:all,-serial,-path,-options</javacArg>
          </javacArgs>
        </configuration>
      </plugin>

这是我看到的输出错误

[warn]   implicit def toDisplayTraversableFunctions[T <: Product](traversable: Traversable[T]): DisplayTraversableFunctions[T] = new DisplayTraversableFunctions[T](traversable)
[warn]                ^
[warn] two warnings found
[error] /Users/jzhang/github/zeppelin/spark/src/main/java/org/apache/zeppelin/spark/DepInterpreter.java:158: error: diamond operator is not supported in -source 1.5
[error]     settings.explicitParentLoader_$eq(new Some<>(Thread.currentThread()

但我确定我使用的是 JDK8.

But I am sure I am usign JDK8.

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Maven 也使用 JDK8

Maven also use JDK8

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024M; support was removed in 8.0
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /Users/jzhang/Java/lib/apache-maven-3.3.9
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

推荐答案

如今设置编译器源和目标版本的典型方法似乎是使用这些预定义的属性:

The quintessential way to set the compiler source and target versions these days seems to be use these pre-defined properties:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

正如您已经注意到的,这些在 maven 中默认为 1.5.这是因为 Maven 总是关于约定优于配置",并且这个默认值是在 Java 1.5 仍然闪亮和新的时候定义的.不幸的是,这很难改变,因为任何仍然依赖 Java 1.5(并且没有指定这些值)的现有项目都可能会中断.

As you already noted, these default to 1.5 in maven. This is because Maven was always about "convention over configuration" and this default value was defined when Java 1.5 was still shiny and new. Unfortunately this has been difficult to change because any existing projects that still depend on Java 1.5 (and had not specified these values) could break.

这篇关于源值 1.5 的错误已过时,将在未来版本中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆