JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.37k stars 1.12k forks source link

1.7.0-alpha01 is incompatible with KGP 2.0.0 when using android projects #5061

Closed ZacSweers closed 1 day ago

ZacSweers commented 6 days ago

Describe the bug 1.7.0-alpha01 fails during gradle sync when used with an android application target.

Caused by: org.gradle.api.InvalidUserDataException: Cannot change hierarchy of dependency configuration ':androidTestImplementation' after it has been included in dependency resolution.
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.preventIllegalMutation(DefaultConfiguration.java:1475)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:1414)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.extendsFrom(DefaultConfiguration.java:404)
    at org.jetbrains.kotlin.gradle.utils.GradleConfigurationUtilsKt.addExtendsFromRelation(gradleConfigurationUtils.kt:25)
    at org.jetbrains.kotlin.gradle.utils.GradleConfigurationUtilsKt.addExtendsFromRelation$default(gradleConfigurationUtils.kt:18)
    at org.jetbrains.kotlin.gradle.plugin.AndroidProjectHandler.addKotlinDependenciesToAndroidSourceSets$addDependenciesToAndroidSourceSet(AndroidProjectHandler.kt:131)
    at org.jetbrains.kotlin.gradle.plugin.AndroidProjectHandler.addKotlinDependenciesToAndroidSourceSets(AndroidProjectHandler.kt:141)
    at org.jetbrains.kotlin.gradle.plugin.AndroidProjectHandler.access$addKotlinDependenciesToAndroidSourceSets(AndroidProjectHandler.kt:52)
    at org.jetbrains.kotlin.gradle.plugin.AndroidProjectHandler$configureTarget$2.invoke(AndroidProjectHandler.kt:98)
    at org.jetbrains.kotlin.gradle.plugin.AndroidProjectHandler$configureTarget$2.invoke(AndroidProjectHandler.kt:88)
    at org.jetbrains.kotlin.gradle.utils.WhenEvaluatedKt$whenEvaluated$2.execute(whenEvaluated.kt:19)
    at org.jetbrains.kotlin.gradle.utils.WhenEvaluatedKt$whenEvaluated$2.execute(whenEvaluated.kt:19)
    at  ...

Affected platforms

Gradle plugin

Versions

To Reproduce Steps to reproduce the behavior:

  1. Checkout this repo: https://github.com/zacsweers/fieldspottr
  2. Change the compose multiplatform version to 1.7.0-alpha01
  3. Try to sync in the IDE

Expected behavior I expect it not to fail during sync

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Him188 commented 5 days ago

FYI: I was able to switch to 1.7.0-alpha01 with Kotlin 2.0.0 and Android. https://github.com/open-ani/ani/pull/502 might help you?

ZacSweers commented 5 days ago

Doesn't help the repro case I've provided above

mshdabiola commented 4 days ago

I am facing same issue

A problem occurred configuring project ':composeApp'.

Cannot change hierarchy of dependency configuration ':composeApp:jvmCompilationApi' after it has been included in dependency resolution.

Caused by: org.gradle.api.InvalidUserDataException: Cannot change hierarchy of dependency configuration ':composeApp:jvmCompilationApi' after it has been included in dependency resolution. at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.preventIllegalMutation(DefaultConfiguration.java:1475)

igordmn commented 1 day ago

A reduced reproducer

./gradlew

One of these changes fixes the issue:

  1. Downgrade Compose to 1.6.11
  2. Remove alias(libs.plugins.aboutLicenses)
  3. Remove org.gradle.configuration-cache=true
igordmn commented 1 day ago

The issue is either in Compose Gradle plugin or in the aboutLicenses plugin - it needs further investigation.

mikepenz commented 1 day ago

I have looked briefly into this problem. And it appears to be caused by the following call accessing the resolvedConfigurations during task execution:

configuration.resolvedConfiguration

Moving the code to the action method of the task will resolve it, however, this won't allow the access to Task.project braking configuration cache as we can't use project at the later time:

invocation of 'Task.project' at execution time is unsupported.

This is shown in this following reproducible example: plugin-demo.zip


To enable support for configuration cache, the plugin has to resolve the dependencies during configuration time. The plugin might require larger refactors like it was done in licensee, if we can't use the dependencies anymore the way they are resolved right now. (cashapp/licensee/issues/72)