4

I am trying to make my project ready for Java 9 and I am running into problems with split packages (artifacts sharing the same package).

My application depends on at least two third-party legacy artifacts (that are built with Java <9). When I run Maven with Java 9, I get:

[ERROR] module myapp reads package P from both A and B

Which is correct, since the package P exists in A.jar and B.jar, but without overlapping classes. I understand that this is a problem for Java 9 and I studied suggested solutions in https://blog.codefx.org/java/java-9-migration-guide/#fixes-2 . To summarize it is either "Fix your code" (not possible, since third-party JAR) or "Run with command line options" (Where the most interesting may be --patch-module <package>=<path-to-jar>). There was another idea here, which said

wrap one of the 3rd party modules (or both) in a simple module, which does nothing but explicitly exports only the package(s) that are actually needed by your module.

But how can I achieve this in Maven (3.5.0), where all I currently have is a <dependency> and the maven-compiler-plugin:3.7.0 - and I don't want to statically repackage third party JARs?

Any hint or pointer to an example would be welcome.

Naman
  • 27,789
  • 26
  • 218
  • 353
taranion
  • 631
  • 1
  • 6
  • 17
  • 2
    To not use modules? – ZhekaKozlov Apr 13 '18 at 06:02
  • As funny as that sounds, that was indeed helpful. When removing the module-info.java from my projects, Maven stopped complaining about the split package. So, thanks. ;-) Still - isn't there a way that allows to keep the module-info.java ? – taranion Apr 13 '18 at 21:22
  • 2
    I'm afraid no. If you create *module-info.java* then you, in fact, start using named modules and module-path with all their limitations. – ZhekaKozlov Apr 14 '18 at 05:48

1 Answers1

0

Please check http://mail-archives.apache.org/mod_mbox/felix-users/200709.mbox/%3CF034315F398DE24C9A76FB51DAFAB709FC9638@nets13ga.ww300.siemens.net%3E

Sample worked for me :

<Export-Package>
  org.hibernate.*;version=${pkgVersion};-split-package:=merge-last                       

</Export-Package>

Same answer at : Why am I getting this "split package" warning?