Multiple versions of a non-exported dependency
njbartlett at gmail.com
Thu Sep 1 07:28:48 UTC 2016
> On 31 Aug 2016, at 20:25, Paul Benedict <pbenedict at apache.org> wrote:
> Neil, but doesn't the prohibition of duplicate packages continue to rear
> its head?
I’m sorry I lost track of the context of this question! If you’re asking whether OSGi is prohibited from loading duplicate packages on Java 9, the answer is no.
In OSGi on Java 9 (or any earlier Java version) we use ClassLoaders to achieve isolation between modules. Therefore we explicitly support overlapping private packages, and even multiple modules with overlapping exported packages (NB the latter feature does require OSGi Release 4 or above, which was released in 2004).
In contrast, Jigsaw/JPMS implements isolation using access control rather than ClassLoader visibility. All modules on the modulepath are loaded into the same ClassLoader, and a single ClassLoader can have at most one definition of each class. The implication is that two modules can conflict purely based on their private internals. If any tool attempts to construct valid module sets for use with the modulepath, it will not be sufficient for that tool to examine only the declared module metadata in module-info.class.
As Alex points out, you can work around this restriction by creating a Layer and mapping modules within that layer to separate ClassLoaders. If you do this then you will still need to manage the visibility of classes and delegation between ClassLoaders. In other words you will have started down the path of implementing your own ClassLoader-based module system comparable to where OSGi was in 1998.
> On Wed, Aug 31, 2016 at 2:21 PM, cowwoc <cowwoc at bbs.darktech.org> wrote:
>> Well, this is unfortunate. As I stated earlier, I fail to see how
>> depending on constant version numbers (not version ranges) fall under
>> the scope of "version selection". Was this case considered/discussed in
>> Not everyone is sold on version ranges (e.g. the vast majority of Maven
>> artifacts I've seen depend on constant versions) and I think this would
>> go a long way towards solving the original "classpath hell" problem.
>> On 2016-08-31 2:55 PM, Neil Bartlett [via jigsaw-dev] wrote:
>>> As Alex points out: your use-case can be supported in Java 9 but only
>>> with the addition of custom ClassLoaders, or by using an existing
>>> ClassLoader-based module system such as OSGi.
>>> The same is also true of Java 8, and Java 7, etc.
>>>> On 31 Aug 2016, at 19:29, Alex Buckley <[hidden email]
>>> </user/SendEmail.jtp?type=node&node=5713366&i=0>> wrote:
>>>> On 8/31/2016 10:56 AM, cowwoc wrote:
>>>>> I recently became aware of the fact that the Jigsaw specification
>>>>> "version-selection" as a non-goal. While I understand how we ended
>>> up here,
>>>>> I am hoping that you were able to support the following (very common)
>>>>> * Module "HelloWorld" depends on modules "Guava" and "JSoup".
>>>>> * Module "Guava" depends on module slf4j version 1 (requires but
>>> does not
>>>>> export it).
>>>>> * Module "JSoup" depends on module slf4j version 2 (requires but
>>> does not
>>>>> export it).
>>>>> * slf4j version 2 and is not backwards-compatible with version 1.
>>>>> What happens at runtime? Will Jigsaw (out of the box, without
>>>>> tools like Maven or OSGI) be smart enough to provide different
>>> versions of
>>>>> slf4j to "Guava" and "JSoup"?
>>>> (You mean Guava/JSoup requires slf4j version 1/2 and does not
>>> "re-export" it a.k.a. 'requires public'.)
>>>> This use case isn't possible on JDK 8 for JARs on the classpath, and
>>> it's not supported on JDK 9 for modular JARs on the modulepath:
>>>> - If you have two versions of a modular JAR slf4j.jar in different
>>> directories on the modulepath, then the first one to be found will
>>> dominate, and that's what will be resolved for both Guava and JSoup.
>>>> - If you have two modular JARs slf4j_v1.jar and slf4j_v2.jar on the
>>> modulepath, and Guava requires slf4j_v1 and JSoup requires slf4j_v2,
>>> then launching 'java -m HelloWorld' will fail. The boot layer will
>>> refuse to map the "same" packages from different slf4j_v* modules to
>>> the application class loader.
>>>> The use case _is_ supported on JDK 9 for modular JARs loaded into
>>> custom loaders of custom layers. That is, the Java Platform Module
>>> System is perfectly capable of supporting the use case -- please see
>>> any of my "Jigsaw: Under The Hood" presentations. The use case just
>>> isn't supported "out of the box" by the 'java' launcher for JARs on
>>> the modulepath.
>>> If you reply to this email, your message will be added to the
>>> discussion below:
>>> To unsubscribe from Multiple versions of a non-exported dependency,
>>> click here
>> View this message in context: http://jigsaw-dev.1059479.n5.
>> Sent from the jigsaw-dev mailing list archive at Nabble.com.
More information about the jigsaw-dev