I have a small test project, containing 2 files:
pom.xml
:
<?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>org.example</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
</project>
and src/main/java/module-info.java
:
module org.example.test {
requires org.json;
}
When I compile with Temurin 17:
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17 35 (build 17 35)
OpenJDK 64-Bit Server VM Temurin-17 35 (build 17 35, mixed mode, sharing)
And Maven 3.6.3 packaged with IntelliJ IDEA, I get this error:
src/main/java/module-info.java:[2,17] module not found: org.json
The json-20210307.jar
file contains this line in META-INF/MANIFEST.MF
:
Automatic-Module-Name: org.json
What further do I need to do to use JPMS in Maven?
CodePudding user response:
If you run
mvn help:effective-pom
you will notice that the project uses the maven compiler version that may be a bit dated. Try explicitly using a newer version and see how it changes things:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <!-- current version -->
</plugin>
</plugins>
</pluginManagement>
</build>