【问题标题】:IntelliJ with JDK10 SDK doesn't compile maven project with 1.8 target带有 JDK10 SDK 的 IntelliJ 无法编译 1.8 目标的 maven 项目
【发布时间】:2018-07-26 06:09:48
【问题描述】:

在一个 maven 项目中考虑以下代码:

import org.w3c.dom.css.CSSStyleDeclaration;

public class Test {
    public static void main(String[] args) {
        CSSStyleDeclaration styleDeclaration = null;
    }
}

其中pom.xml 包含maven-compiler-plugin 插件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.serce.jdk10mvntest</groupId>
    <artifactId>jdk10mvntest</artifactId>
    <version>1.0-SNAPSHOT</version>

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

这个项目可以用maven编译,没有错误。但是,当它使用 JDK10 SDK 从 IntelliJ 编译时,会出现 Error:(1, 27) java: package org.w3c.dom.css does not exist 错误。如果源更改为&lt;source&gt;10&lt;/source&gt;,错误就会消失。我预计问题可能与jigsaw 有关,但我不能使用--add-modules ...,因为javacoption --add-modules not allowed with target 1.8 出错。

是否有任何解决方法可以让我使用带有 JDK10 SDK 和 1.8 源和目标的 IntelliJ 编译此代码?


IntelliJ:2018.2
Java:Java HotSpot(TM) 64-Bit Server VM 18.3(build 10.0.1+10,混合模式)

【问题讨论】:

  • intelliJ 和 JDK 10 哪个版本?您的项目设置是什么(SDK/模块语言级别等)?我可以确认,在我将 SDK 设置为 10 时,在 IJ 和 jdk-10 的 2018.2 上工作正常。
  • @nullpointer 我添加了版本。
  • 好的,我正在使用18.3 (build 10+46)Maven 3.5.4,如果这可能是不同的话。如果需要可以分享屏幕截图,它适用于我的 source&target 1.8 和 SDK 10。
  • @nullpointer 我不确定 maven 是否会影响这一点,我使用 IntelliJ 编译项目,maven 与两个 JDK 都兼容。
  • 我在 youtrack 上填写了一个问题,youtrack.jetbrains.com/issue/IDEA-196336

标签: java intellij-idea compilation java-10 java-platform-module-system


【解决方案1】:

禁用“使用--release选项进行交叉编译”:

更多详情请参阅this issuemy another answer about this option

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 2016-08-05
    • 2017-10-29
    • 2015-10-14
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多