3

I'm attempting to upgrade a 15 year old Maven multimodule project to Java 11, and the module system that was introduced in Java 9. Since the project is built using Maven, all dependencies are pretty clear. First I want to do this using the automatic module names, in order not to also introduce upgraded artifacts (if not absolutely required).

Eclipse is pretty helpful in this process, autocompleting the automatic module names in the module-info.java. For example:

requires dom4j;

But if I compile with Maven, I get errors about that it cannot find the modules Eclipse just autocompleted in there.

module-info.java:[29,18] module not found: dom4j

I am using Maven's compiler plugin 3.7.0 (3.8.0 gives a NullPointerException as per https://jira.apache.org/jira/browse/MCOMPILER-355) I suspect Maven is setting the jars up on the classpath instead of on the modulepath, but the compiler's plugin debug output does not log that.

How can I make Maven correctly handle those modules?

7
  • First you have defined a required module which does not exist as shown in the error output. This means you have to use a higher version which has a module descriptor. Furthermore the referenced issue is closed. Furthermore without more information is not possible to help in particular you should use the most recent version of maven-compiler-plugin and also update all plugins you are using to the most recent one cause there had been a larger number of changes related to module support etc. Also would it be helpful to have your full pom files and module-info.java file as well....
    – khmarbaise
    Commented Mar 20, 2019 at 9:38
  • Downloading and manually compiling maven-compiler-plugin.3.8.1-SNAPSHOT (and using that) results in sensible errors over the modules, so both 3.7.0 and 3.8.0 apparently are not capable of handling this project structure. To be continued.
    – tbeernot
    Commented Mar 20, 2019 at 9:38
  • Unfortunately it is not helpful to say that a SNAPSHOT version makes it different. Helpful would be to have an example project which shows the problem and makes it possible to reproduce the issue. Furthermore if you think this is really a bug please file in an issue with the appropriate information. Without knowing your project structure it is not possible to help in any way...
    – khmarbaise
    Commented Mar 20, 2019 at 9:42
  • 1
    This is a 15 year old project, you do not want to list the whole structure, it will scare people. Essence of the problem is that maven-compiler-plugin 3.7.0 apparently does not put (all) automatic named modules on the modulepath, and 3.8.0 has a NullPointerException. Yes, the NPE issue is closed, hence the use of 3.8.1 (SNAPSHOT, since it is not released yet). So if anyone runs into the issue, (s)he will know what to do.
    – tbeernot
    Commented Mar 20, 2019 at 9:47
  • Sorry but this does not help. automatic module names are the wrong way..you have to use MANIFEST.MF (Automatic-Module-Name entry) without information not possible help...
    – khmarbaise
    Commented Mar 20, 2019 at 9:52

1 Answer 1

3

I was running into the same issue. Adding

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>
    </plugins>
</build>

to my pom solved the problem for me...

Maven version 3.9.0 seems to be buggy and will not find the module although the dependency is using an Automatic-Module-Name. Downgrading to version 3.8.1 helps.

2
  • Yes, that wasn't released yet at the time I made the post. 3.8.1-SNAPSHOT did work indeed
    – tbeernot
    Commented Jul 1, 2019 at 19:18
  • No, still the same problem
    – ed22
    Commented Sep 3, 2022 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.