square/moshi

JDK9 Modules: module reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi

unoexperto opened this issue · 1 comments

Hi folks, I'm making unsuccessful attempt to use Java 9 Modules and wanted to find out if moshi libraries support it. Here is build.gradle.kts of my small project

plugins {
    id("org.javamodularity.moduleplugin")
}

project.description = "Collections of extension functions and classes for Moshi json serializer."

dependencies {
    implementation(kotlin("stdlib", Versions.kotlin))

    implementation("com.squareup.moshi:moshi:${Versions.moshi}")
    implementation("com.squareup.moshi:moshi-kotlin:${Versions.moshi}")
    implementation("com.squareup.moshi:moshi-adapters:${Versions.moshi}")
    implementation("io.netty:netty-buffer:${Versions.nettyBuffer}")

    testImplementation(kotlin("test-junit5", Versions.kotlin))
}

and module-info.java contains

module com.walkmind.extensions_moshi {
    requires transitive kotlin.stdlib;
    requires com.squareup.moshi;
    requires com.squareup.moshi.adapters;
    requires com.squareup.moshi.kotlin;
    exports com.walkmind.extensions.moshi;
}

on attempt to compile it I get an error:

> Task :extensions-moshi:compileJava FAILED
error: the unnamed module reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: the unnamed module reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module com.squareup.moshi.kotlin reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module com.squareup.moshi.kotlin reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module com.squareup.moshi.adapters reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module com.squareup.moshi.adapters reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module annotations reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module annotations reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module io.netty.common reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module io.netty.common reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module io.netty.buffer reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module io.netty.buffer reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module okio reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module okio reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
error: module com.squareup.moshi reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi
error: module com.squareup.moshi reads package com.squareup.moshi from both com.squareup.moshi.adapters and com.squareup.moshi.kotlin
/home/expert/work/sideprojects/unoexperto/extensions/extensions-moshi/src/main/java/module-info.java:1: error: module com.walkmind.extensions_moshi reads package com.squareup.moshi from both com.squareup.moshi and com.squareup.moshi.adapters
module com.walkmind.extensions_moshi {
^
17 errors

Googling tells me that so called "split packages" is very common with Java 9 Module System and indeed I see that com.squareup.moshi package is present in multiple moshi libraries.

What am I missing ?

This is tracked by #1160. There are new versions of the offending classes in .adapters and .kotlin which allow the module system to succeed but only if you patch the jars (or use a build system that allows you to automate patching, such as a Gradle transform).

This library predates Java 9 and the module path and it has maintained binary compatibility throughout that period. If there ever is a breaking change done (which will also come with new Maven artifactId and package name) these offending types will be removed.