6

So, I'm trying to migrate a tool from Java 8 to Java 11.
I did the first step to make it work without modules and the code compiles successfully.

Now I'm trying to add the module-info.java, and I first faced issues because of the libraries used in my tool. Some are already compatible with Java 11 (e.g. Lombok) but some others are not, so I'm trying to import them using the requires and the artifactId name.
But I seem stuck because of my Maven model & Maven model builder dependency as I get the following error when building:

[ERROR] the unnamed module reads package org.apache.maven.model.merge from both maven.model.builder and maven.model
[ERROR] module maven.model.builder reads package org.apache.maven.model.merge from both maven.model.builder and maven.model
[ERROR] module maven.model reads package org.apache.maven.model.merge from both maven.model.builder and maven.model

What should I do for this kind of error? It seems I need both (build still fails if I comment one or the other). Does it mean I cannot add modules to my tool because of my dependencies?
N.B.: The libraries are set to their latest version (i.e. 3.6.3)

Naman
  • 27,789
  • 26
  • 218
  • 353
Xendar
  • 466
  • 1
  • 6
  • 15
  • The module system does not allow split packages. Are there newer versions of your dependencies that may have fixed the problem? – Slaw Mar 29 '20 at 14:52
  • I tried upgrading to the latest one (3.6.3) but the issue persists – Xendar Mar 29 '20 at 15:16
  • I am also facing the same issue. I got compile by excluding like this following but it will cause run time issues, just wondering is there any other module to exclude? implementation ('org.apache.maven:maven-resolver-provider:3.6.3') { exclude group: 'org.apache.maven.model.merge' , module: 'maven-model-merge' } – Tharik Kanaka Sep 29 '20 at 06:10
  • Well, I didn't manage to solve this, so I abandoned the move to JPMS... What a shame – Xendar Sep 30 '20 at 18:46

1 Answers1

0

I "fixed" this using the maven-exec-plugin as described in the answer to this question.

Edit: When running the main class through the maven-exec-plugin, the compiler does (for some reason unknown to me) not complain anymore about the conflicts.

Aron Hoogeveen
  • 437
  • 5
  • 16
  • I'm not sure I understand the link between the exec plugin and this split package issue – Xendar Feb 23 '21 at 22:04
  • Well IntelliJ complained about some packages that where exported to the same module (just as you described in you question), and I could not seem to get it fixed. However, when I run the main class via the exec plugin, those conflicting exports are not there anymore, and you can then run your program via the plugin. It is a dirty "solution" but it "works" – Aron Hoogeveen Feb 24 '21 at 09:13
  • Oh, this is surprising! – Xendar Feb 25 '21 at 13:17