问题
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.
回答1:
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?
来源:https://stackoverflow.com/questions/49805394/use-third-party-artifacts-with-split-packages-in-maven-and-java-9