Java 6 类 when 1.7 is configured in Intellij/maven with scala plugin

Java 6 classes when 1.7 is configured in Intellij/maven with scala plugin

如屏幕截图所示,module/project 设置为 jdk 1.7

项目/sdk 设置为 7:

模块设置为 jdk 7:

但是从 javap 我们看到 java6 (50) ??

a) 确认 class 刚刚编译 (7/22/15 @18:14) :

ls -l ./target/classes/org/yardstickframework/spark/DataGenerator.class
-rw-r--r--  1 steve  staff  3829 Jul 22 18:14 ./target/classes/org/yardstickframework/spark/DataGenerator.class

b) java 是哪个版本?

javap -verbose ./target/classes/org/yardstickframework/spark/DataGenerator.class | grep ver
  minor version: 0
  major version: 50

注意:pom.xml 将语言级别设置为 jdk7

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

更新 根据我的建议 运行 从命令行编译:

mvn clean compile

这会在 jdk6 /major version=50 中产生 also。现在为什么会这样?我正在检查 POM 以查看是否存在其他异常情况。

另一个更新 根据 Roman 的要求:这是 maven 输出

$mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10", arch: "x86_64", family: "mac"

另一个更新 ElliottFrisch 建议对 maven 编译器插件进行一些补充。这是更新的部分:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <verbose>true</verbose>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

好吧,我对此有点不好意思。这是一个 scala 项目,class 文件是 scala-maven 插件的输出。因此,所有这些 Maven 编译器设置仅适用于 java source 文件。很抱歉那些失踪的大人物。

在 scala-maven-plugin 中获得正确版本的方法并不容易确定:但幸运的是有人已经弄明白了:

http://xflin.blogspot.com/2013/08/mixed-scala-and-java-in-maven-project.html

这里是关键部分:

    <recompileMode>incremental</recompileMode>
    <args>
      <arg>-target:jvm-1.7</arg>
    </args>
    <javacArgs>
      <javacArg>-source</javacArg><javacArg>1.7</javacArg>
      <javacArg>-target</javacArg><javacArg>1.7</javacArg>
    </javacArgs>

这属于正常的 scala-maven-plugin 部分,看起来像:

        <plugin>
            <version>3.2.1</version>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <scalaCompatVersion>${scala.version}</scalaCompatVersion>
                <scalaVersion>${scala.binary.version}</scalaVersion>
                <jvmArgs>
                    <jvmArg>-Xms512m</jvmArg>
                    <jvmArg>-Xmx1024m</jvmArg>
                </jvmArgs>
              <recompileMode>incremental</recompileMode>
              <args>
                <arg>-target:jvm-1.7</arg>
              </args>
              <javacArgs>
                <javacArg>-source</javacArg><javacArg>1.7</javacArg>
                <javacArg>-target</javacArg><javacArg>1.7</javacArg>
              </javacArgs>
          </configuration>
        </plugin>

将那部分添加到 Scala 插件后,我们现在拥有:

$javap -verbose ./target/classes/org/yardstickframework/spark/DataGenerator.class | grep ver
  minor version: 0
  major version: 51