How can I handle split packages in automatic modules?

允我心安 提交于 2020-01-01 09:01:32

问题


I am currently testing to migrate an existing application to Jigsaw Modules. One of my modules uses ElasticSearch along with its Groovy Plugin.

  • org.elasticsearch:elasticsearch
  • org.elasticsearch.module:lang-groovy

Unfortunately, they share a split package, so mvn install gives me:

x reads package org.elasticsearch.script.groovy from both lang.groovy and elasticsearch

once for each required module in the descriptor, where x is the name of each module.

I assume that a newer elasticsearch version will have eliminated the split package by the time Java 9 is final, but is there generally a way to handle split packages in legacy dependencies?

I was hoping to be able to have those on the the classpath instead of the module path, but after reading this conversation on the mailing list it seems that there is no way to tell the Maven compiler to do so.


maven 3.3.9 - maven-compiler-plugin 3.6.0 - jdk9-ea+149 - elasticsearch 2.3.3


回答1:


After some more testing, I think there are a few options which should tackle many (but definitely not all) 3rd party split package situations.

  1. Clean up dependencies - maybe a dependency isn't actually needed or can be replaced by a newer (or more distinct) JAR
  2. Restructure your own module into two modules, each reading the package from one of both 3rd party modules (if possible/reasonable)
  3. wrap one of the 3rd party modules (or both) in a simple module, which does nothing but explicitly export only the package(s) that are actually needed by your module.

Depending on the situation, one of these options might be a good fit to resolve the split package problem. But none of them can handle situations in which a coherent piece of code actually needs to access classes from both parts of the split package.



来源:https://stackoverflow.com/questions/41385229/how-can-i-handle-split-packages-in-automatic-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!