Not finding automatic modules when compiling Java Application

277 views Asked by At

I have a large multi module (100s) Java project and have been experimenting with adopting java module support. This is using Java 17 (temurin), gradle 7.6, and IntelliJ 2022.3.

I have hit a couple of stubborn errors with java modules where the module cannot be found.

I have one project which has some java code that uses plexus ie:

import org.codehaus.plexus.util.Base64;

...
byte[] encodedAuthorizationString = Base64.encodeBase64(authorizationString.getBytes(StandardCharsets.US_ASCII));

It has a gradle dependency

implementation 'org.codehaus.plexus:plexus-utils'

This has a version constraint in our main build.gradle (just salient lines included):

plexusVersion = '3.5.0'
implementation("org.codehaus.plexus:plexus-utils:${plexusVersion}")

Prior to adding module support this is working fine.

Now, with a module-info.java:

module egeria.open.metadata.implementation.adapters.open.connectors.rest.client.connectors.spring.rest.client.connector.main {
    requires egeria.open.metadata.implementation.adapters.authentication.plugins.http.helper.main;
    requires egeria.open.metadata.implementation.adapters.open.connectors.rest.client.connectors.rest.client.connectors.api.main;
    //requires egeria.open.metadata.implementation.adapters.open.connectors.rest.client.connectors.rest.client.factory.main;
    requires egeria.open.metadata.implementation.frameworks.open.connector.framework.main;
    requires plexus.utils;
    requires org.slf4j;
    requires spring.core;
    requires spring.web;

    exports org.odpi.openmetadata.adapters.connectors.restclients.spring;
}

I am getting a compile error

Task ':open-metadata-implementation:adapters:open-connectors:rest-client-connectors:spring-rest-client-connector:compileJava' is not up-to-date because:
  Task has failed previously.
The input changes require a full rebuild for incremental task ':open-metadata-implementation:adapters:open-connectors:rest-client-connectors:spring-rest-client-connector:compileJava'.
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
Compiling with toolchain '/Library/Java/JavaVirtualMachines/temurin-19.jdk/Contents/Home'.
Compiling with JDK Java compiler API.
/Users/jonesn/IdeaProjects/egeria/v4/open-metadata-implementation/adapters/open-connectors/rest-client-connectors/spring-rest-client-connector/src/main/java/module-info.java:6: error: module not found: plexus.utils
    requires plexus.utils;
                   ^
1 error

This is despite the fact, that having downloaded the jar file, the automatic module name looks to be what I am using ie:

jar --file=/Users/jonesn/Downloads/plexus-utils-3.5.0.jar --describe-module
No module descriptor found. Derived automatic module.

[email protected] automatic
requires java.base mandated
contains org.codehaus.plexus.util
contains org.codehaus.plexus.util.cli
contains org.codehaus.plexus.util.cli.shell
contains org.codehaus.plexus.util.dag
contains org.codehaus.plexus.util.introspection
contains org.codehaus.plexus.util.io
contains org.codehaus.plexus.util.reflection
contains org.codehaus.plexus.util.xml
contains org.codehaus.plexus.util.xml.pull

I am seeing the same error with kafka-clients

For most other code, including those libraries without full module support, all is good....

  • tried various compilers, such as openjdk 17 & temurin 19
  • built at cli & within IntelliJ

I was expecting this module to resolve ok

I have also reviewed Java 9 automatic modules not found but note that other automatic modules (including org.slf4j) are working just fine

I should add that I could refactor this code to use java.util.Base64 (probably makes sense)... but I'm still confused as to why the module error, which I also see in another project with 'kafka.clients'

0

There are 0 answers