Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 926
SerCe Avatar asked Jul 26 '18 06:07

SerCe


1 Answers

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

--release

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

like image 113
CrazyCoder Avatar answered Oct 06 '22 11:10

CrazyCoder