Running into an issue with Gradle and Kotlin Multi...
# gradle
m
Running into an issue with Gradle and Kotlin Multiplatform:
Copy code
Execution failed for task ':mewsic-plugin-api:compileDebugKotlinAndroid'.
> Error while evaluating property 'friendPathsSet$kotlin_gradle_plugin_common' of task ':mewsic-plugin-api:compileDebugKotlinAndroid'.
   > Could not resolve all files for configuration ':mewsic-plugin-api:debugCompileClasspath'.
      > Could not resolve com.google.guava:guava:33.2.1-android.
        Required by:
            project :mewsic-plugin-api
         > Cannot find a version of 'com.google.guava:guava' that satisfies the version constraints:
              Dependency path 'dev.uninit:mewsic-plugin-api:1.0.0' --> 'com.google.guava:guava:33.2.1-android'
              Dependency path 'dev.uninit:mewsic-plugin-api:1.0.0' --> 'com.google.guava:guava:33.2.1-jre'
              Constraint path 'dev.uninit:mewsic-plugin-api:1.0.0' --> 'com.google.guava:guava:{strictly 33.2.1-android}' because of the following reason: version resolved in configuration ':mewsic-plugin-api:debugRuntimeClasspath' by consistent resolution
With gradle code (in
kotlin { sourceSets {
)
Copy code
androidMain {
    dependencies {
        implementation("com.google.guava:guava:${Versions.guava}-android")
    }
}

appMain {  // Shared between androidMain and desktopMain
    dependencies {
        compileOnly("com.google.guava:guava:${Versions.guava}-jre")  // CompileOnly because the artifact differs between Android and Desktop
    }
}

desktopMain {
    dependencies {
        implementation("com.google.guava:guava:${Versions.guava}-jre")
    }
}
m
You can probably just leave the dependency out of
appMain
since the commonizer will find all the common APIs in the child source sets.
m
The commonizer only runs on native sourcesets, leaving it out in
appMain
results in guava's MapMaker being unresolved in that sourceset.
t
hmm, which Kotlin Gradle Plugin version are you using?
and could you provide a repro?
m
This is using 2.0.0 of the Kotlin Gradle Plugin
I believe the following would result in the same issue when building the Android target.
Copy code
plugins {
   kotlin("multiplatform") version "2.0.0"
}

kotlin {
    androidTarget()
    jvm("desktop")

    sourceSets {
        val appMain by creating {
            dependencies {
                compileOnly("com.google.guava:guava:33.2.1-jre")
            }
        }

        androidMain {
            dependsOn(appMain)

            dependencies {
                implementation("com.google.guava:guava:33.2.1-android")
            }
        }



        val desktopMain by getting {
            dependsOn(appMain)

            dependencies {
                implementation("com.google.guava:guava:33.2.1-jre")
            }
        }
    }
}
t
cc @Anton Lakotka [JB] @Evgenii Mazhukin
a
I think this needs deep, dark, Gradle magic to resolve. The Gradle docs has an example specifically about Guava https://docs.gradle.org/8.8/userguide/component_metadata_rules.html#making_variants_encoded_in_versions_explicit
although there's a semi-official Gradle plugin that will help with awkward dependencies like Guava, and it says that Guava now publishes valid variants so workarounds shouldn't be necessary 🤔 https://github.com/gradlex-org/jvm-dependency-conflict-resolution/blob/v2.1.1/README.MD#notes-on-the-plugins-history
222 Views