Basically, just add this maven build compiler plugin portion to your main project Maven POM.xml
to specify which JDK9+ modules MUST BE added for javac compilation purposes.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> ... <properties> <java.version>11</java.version> ... </properties> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <!-- JDK9+ Add Module MAGIC happens below... --> <!-- Add implicit default JDK9+ java.se explicitly --> <!-- Add explicit java.desktop for import java.awt.*; --> <compilerArgs> <arg>--add-modules</arg> <arg>java.se,java.desktop</arg> </compilerArgs> </configuration> </plugin> </plugins> </build> </project>
as explained here:
https://www.baeldung.com/java-9-modularity
For other common missing JDK10+ modules, please refer to:
http://cr.openjdk.java.net/~iris/se/10/pfd/java-se-10-pfd-spec-01/api/overview-summary.html
requires java.desktop;inside your modules.java