In my Java 21 project, I’m trying to use the package io.jsonwebtoken.Jwts
in the library jjwt-api
.
This dependency has no module-info.java
and no Automatic-Module-Name
-entry inside of the MANIFEST.MF
.
IntelliJ 2024.1.3 suggests it requires jjwt-api
, and if I run:
import java.lang.module.ModuleFinder;
import java.nio.file.Path;
ModuleFinder.of(Path.of("C:\Users\...\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt-api\0.12.5\ea8243e36f16c2834ad69a048ed8a24aa9dd3e79\jjwt-api-0.12.5.jar"))
.findAll()
.forEach(System.out::println);
It also finds and suggests that name (following the spec).
The Problem
If I try to compile my application, I get the error:
Fehler: Modul nicht gefunden: jjwt.api
requires jjwt.api;
^
(German for: “Error: Module not found”)
build.gradle.kts
dependencies {
implementation("io.jsonwebtoken:jjwt-api:0.12.5")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.5")
runtimeOnly("io.jsonwebtoken:jjwt-gson:0.12.5")
}
Question
Is this an IntelliJ, Gradle, or Javac error, and how can I fix it?
2
I have now fixed the error by using the extra-java-module-info
plugin.
I simply added the following lines to my build.gradle.kts
:
plugins {
// other plugins
id("org.gradlex.extra-java-module-info") version "1.8"
}
extraJavaModuleInfo {
deriveAutomaticModuleNamesFromFileNames.set(true)
}
(I won’t accept this as the answer tho, as I hope that there is a better, more “native” way of doing including automatic modules without the use of external gradle plugins)
2