Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved reference error with Kotlin 2.1 and API dependencies #875

Open
vinceglb opened this issue Dec 1, 2024 · 4 comments
Open

Unresolved reference error with Kotlin 2.1 and API dependencies #875

vinceglb opened this issue Dec 1, 2024 · 4 comments

Comments

@vinceglb
Copy link

vinceglb commented Dec 1, 2024

After upgrading my library from Kotlin 2.0.21 to 2.1.0, my build broke. After some investigation, I realized that the plugin was breaking the build in a specific case: when using api dependencies. Here is the setup:

Library root

gradle/libs.versions.toml

kotlin = "2.1.0"
vanniktech-mavenPublish = "0.30.0"

Then, configure the POM as described here: https://vanniktech.github.io/gradle-maven-publish-plugin/central/#configuring-maven-central

gradle.properties

...

# OSS
SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true

# Lib
GROUP=...
VERSION_NAME=...

POM_NAME=...
POM_DESCRIPTION=...

... continue to apply configs

Package lib-a

LibA.kt

class LibA

Package lib-b

build.gradle.kts

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.vanniktech.mavenPublish)
}

kotlin {
    ...
    sourceSets {
        commonMain.dependencies {
            // Uses api here
            api(projects.libA)
        }
    }
    ...
}

Package lib-c

build.gradle.kts

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.vanniktech.mavenPublish)
}

kotlin {
    ...
    sourceSets {
        commonMain.dependencies {
            implementation(projects.libB)
        }
    }
    ...
}

main.kt

fun main() {
    val lib = LibA()   // Unresolved reference: LibA with Kotlin 2.1.0 but works with Kotlin 2.0.21
}

I realized that:

  • if I use Kotlin 2.0.21, everything will work as expected.
  • if I remove the plugin configs from the gradle.properties, even when using Kotlin 2.1, it fixes the build with no more unresolved reference error.

If you have any questions, don't hesitate!

@gabrielittner
Copy link
Collaborator

Could you share a project that reproduces it?

@vinceglb
Copy link
Author

vinceglb commented Dec 2, 2024

Sure, here is a reproduction repository: https://github.com/vinceglb/MavenPublishExample

You can visit LibC.kt or App.kt to see errors in Android Studio.

Also, you can run one of these commands to have errors at build time:

./gradlew build
./gradlew :lib-c:compileCommonMainKotlinMetadata

If you remove all the plugin properties bellow # OSS in gradle.properties, it will fix the problem.

Also, if you keep properties in gradle.properties but downgrade kotlin to 2.0.21, it will fix the problems too.

@gabrielittner
Copy link
Collaborator

Thank you for the reproducer, it helped a lot. I was able to narrow it down to the GROUP property and then was also able to generally reproduce it with the regular maven-publish plugin. In particular setting the groupId on the kotlinMultiplatform publication (this is the "common" artifact that gets published) will trigger the issue. I've filed an issue in the Kotlin issue tracker for this https://youtrack.jetbrains.com/issue/KT-73620

@vinceglb
Copy link
Author

vinceglb commented Dec 2, 2024

Thanks a lot for your reactivity! I'll follow the issue on YouTrack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants