IntelliJ with JDK10 SDK doesn't compile maven project with 1.8 target
Asked Answered
H

1

15

Consider the following code in a maven project:

import org.w3c.dom.css.CSSStyleDeclaration;

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

Where pom.xml contains maven-compiler-plugin 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>

This project can be compiled using maven with no errors. However, when it's compiled from IntelliJ with JDK10 SDK, it gives Error:(1, 27) java: package org.w3c.dom.css does not exist error. If the source is changed to <source>10</source> the error disappears. I expect that the problem might be related to jigsaw, but I can't use --add-modules ... because javac errors out with option --add-modules not allowed with target 1.8.

Are there any workarounds that will allow me to compile this code using IntelliJ with JDK10 SDK and 1.8 source and target?


IntelliJ: 2018.2
Java: Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

Horripilation answered 26/7, 2018 at 6:9 Comment(5)
Which version of intelliJ and JDK 10? And what are your project settings(SDK/Modules language level etc) ? I can confirm, works fine for me on 2018.2 of IJ and jdk-10 with same configurations while I am setting the SDK to 10.Gilman
@nullpointer I added the versions.Horripilation
Okay, I am using 18.3 (build 10+46) and Maven 3.5.4 if that could be the difference. If required can share the screenshot, that it works with source&target 1.8 and SDK 10 for me.Gilman
@nullpointer I'm not sure if maven can affect this, I use IntelliJ to compile the project, maven works well with both JDKs.Horripilation
I filled an issue on youtrack, youtrack.jetbrains.com/issue/IDEA-196336Horripilation
C
14

Disable the "Use --release option for cross-compilation":

--release

See this issue for more details and my another answer about this option.

Cotterell answered 29/7, 2018 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.