How can I handle split packages in automatic modules?

936 views Asked by At

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

There are 1 answers

0
peterp On

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.