gradlex-org/extra-java-module-info

can't determined while same package in different library

arjenzhou opened this issue · 3 comments

I am trying transform zookeeper library to module. In which same package org.apache.zookeeper.server.persistence found in zookeeper-jute-{version}.jar and zookeeper-{version}.jar.

plugins {
    id 'de.jjohannes.extra-java-module-info'
}

dependencies {
    implementation('org.apache.zookeeper:zookeeper:3.7.0') {
        exclude group: 'log4j'
        exclude group: 'org.slf4j'
    }
}

extraJavaModuleInfo {
    module("zookeeper-3.7.0.jar", "org.apache.zookeeper.zookeeper", "3.7.0") {
        requires("org.apache.jute")
        requires("org.apache.yetus.audience")
        exports("org.apache.zookeeper")
    }
    module("zookeeper-jute-3.7.0.jar", "org.apache.jute", "3.7.0") {
        requires("org.apache.yetus.audience")
        exports("org.apache.jute")
    }
    module("audience-annotations-0.12.0.jar", "org.apache.yetus.audience", "0.12.0") {
        exports("org.apache.yetus.audience")
    }
}

It wil throws

Error occurred during initialization of boot layer
java.lang.LayerInstantiationException: Package org.apache.zookeeper.server.persistence in both module org.apache.jute and module org.apache.zookeeper.zookeeper

while trying to run

ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 1000, null);

Unfortunately, ☹️ this is an issue with the Java Module System, which I also regularly forget about: It is not allowed to have the same package in two Jars even if the package is not exported.

At some point, I was thinking that exactly what you are doing could be a solution to mitigate the split package situation of some non-module libraries. Unfortunately, it is not the case.

I don't see a solution how you could use both Jars together in a "full" module setup. This is frustrating...

There is an attempt I haven't followed up with to allow this plugin to merge two Jars into one as a band aid for such situations: #1 (comment)

I might consider giving that another try. Would that "workaround" help you? (Of course contributions are always welcome!)

The plugin (with version 0.12) now supports merging of Jars which have the 'split package' issue. See:
https://github.com/jjohannes/extra-java-module-info#what-do-i-do-in-a-split-package-situation

Maybe this is helpful for you @arjenzhou.

@jjohannes Thanks, I will try it later.