【问题标题】:IntelliJ Idea Maven plugin attempts to compile in Java 1.7 when configured for 1.8 (Mac)IntelliJ Idea Maven 插件在配置为 1.8 (Mac) 时尝试在 Java 1.7 中编译
【发布时间】:2014-09-24 20:26:25
【问题描述】:

我正在尝试针对示例项目运行 maven 目标,同时启动一个新项目。我是 Mac 和 IntelliJ 的新手(我在评估它时正在与 Eclipse Luna 一起运行社区版)。这一切都在 Eclipse 和终端中工作。

我遇到的问题是让 Maven 在 Java 8 中运行它。我已将 JAVA_HOME 配置为 1.8,将项目 JDK 设置为 1.8,将语言级别设置为 1.8,等等。代码编译(使用 lambdas)所以 1.8显然是 IntelliJ 正在使用的。但是 Maven 插件似乎不想尊重该设置。

这是 maven 目标配置(使用 Deploy 目标): 工作目录:/Users/brian.trezise/IdeaProjects/exampleservice 命令行:全新安装 tomcat7:run

当我从 Maven Projects 弹出窗口执行目标时,它会执行以下操作:

/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/bin/java -Dmaven.home=/usr/local/Cellar/maven/3.2.2/libexec -Dclassworlds.conf=/usr/local/Cellar/maven/3.2.2/libexec/bin/m2.conf -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/local/Cellar/maven/3.2.2/libexec/boot/plexus-classworlds-2.5.1.jar:/Applications/IntelliJ IDEA 13 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.4 clean install tomcat7:run

在 Maven 尝试编译(下载所有依赖项等)之前,它似乎运行良好,然后我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project inin-example-app: Compilation failure
[ERROR] /Users/brian.trezise/IdeaProjects/exampleservice/src/main/java/com/inin/example/controller/PingController.java:[53,49] lambda expressions are not supported in -source 1.7
[ERROR] (use -source 8 or higher to enable lambda expressions)

我不确定如何将其配置为使用“-source 8”(如果我将其添加到命令行,它就会失败)。

有人愿意同情 IntelliJ 新手吗?

【问题讨论】:

    标签: java macos maven intellij-idea


    【解决方案1】:

    您的 Maven 构建中似乎缺少编译器插件,因此默认为 1.7,请尝试将以下内容添加到您的 pom.xml build 部分

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

    【讨论】:

      【解决方案2】:

      我尝试对 Intellij IDEA 进行如下更改:

      1.

      File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler >> project bytecode version: 1.8 >> Per-module bytecode version: 1.8
      

      2.

      File >> Project Structure >> Project Settings >> Project >> SDK : 1.8, Project Language : 8 - Lambdas
      File >> Project Structure >> Project Settings >> Modules >> abc : Language level: 8 - Lambdas
      

      但没有任何效果,我一保存它就将版本恢复为 java 1.5。

      但是,将以下行添加到根(项目级别) pom.xml 让我解决了上述问题:(这两个选项都对我有用)

      选项 1:

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

      选项 2:

      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                  </configuration>
              </plugin>
          </plugins>
      </build>
      

      原帖于:IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 2014-11-21
        • 2018-07-02
        • 2016-01-06
        • 1970-01-01
        • 2020-05-27
        • 2014-09-29
        相关资源
        最近更新 更多