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)

SerCe
  • 5,826
  • 2
  • 32
  • 53
  • 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. – Naman Jul 26 '18 at 07:28
  • @nullpointer I added the versions. – SerCe Jul 26 '18 at 07:33
  • 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. – Naman Jul 26 '18 at 07:36
  • @nullpointer I'm not sure if maven can affect this, I use IntelliJ to compile the project, maven works well with both JDKs. – SerCe Jul 29 '18 at 05:50
  • I filled an issue on youtrack, https://youtrack.jetbrains.com/issue/IDEA-196336 – SerCe Jul 29 '18 at 05:50

1 Answers1

14

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

--release

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

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904