autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.67k stars 115 forks source link

1.29.0 upgrade causes early failure #1115

Closed yschimke closed 4 months ago

yschimke commented 5 months ago

Example PR https://github.com/google/horologist/pull/2009

Build scan link N/A - I think failing during setup

Plugin version

1.29.0

Gradle version 8.5

JDK version 17

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version 1.9.21

(Optional) Android Gradle Plugin (AGP) version 8.2.2

Describe the bug

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':compose-material'.
> 
                  It is too late to add actions as the callbacks already executed.
                  Did you try to call beforeVariants or onVariants from the old variant API
                  'applicationVariants' for instance ? you should always call beforeVariants or
                  onVariants directly from the androidComponents DSL block.

* Try:
> Run with --info or --debug option to get more log output.
> Get more help at https://help.gradle.org.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':compose-material'.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:84)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:77)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.access$500(LifecycleProjectEvaluator.java:55)
...
Caused by: java.lang.RuntimeException: 
                It is too late to add actions as the callbacks already executed.
                Did you try to call beforeVariants or onVariants from the old variant API
                'applicationVariants' for instance ? you should always call beforeVariants or
                onVariants directly from the androidComponents DSL block.

    at com.android.build.api.extension.impl.OperationsRegistrar.addOperation(OperationsRegistrar.kt:44)
    at com.android.build.api.extension.impl.AndroidComponentsExtensionImpl.onVariants(AndroidComponentsExtensionImpl.kt:74)
    at com.android.build.api.variant.AndroidComponentsExtension.onVariants$default(AndroidComponentsExtension.kt:114)
    at com.autonomousapps.subplugin.ProjectPlugin.configureAndroidLibProject(ProjectPlugin.kt:214)
    at com.autonomousapps.subplugin.ProjectPlugin.access$configureAndroidLibProject(ProjectPlugin.kt:55)
    at com.autonomousapps.subplugin.ProjectPlugin$apply$1$1$2.execute(ProjectPlugin.kt:114)
    at com.autonomousapps.subplugin.ProjectPlugin$apply$1$1$2.execute(ProjectPlugin.kt:112)
    at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:261)
    at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:258)

To Reproduce Steps to reproduce the behavior:

  1. run any gradle command
yschimke commented 5 months ago

Possibly relevant - we set dependency.analysis.autoapply=false and apply separately

gabrielittner commented 5 months ago

We're also seeing this on our internal project and we also disabled auto apply.

autonomousapps commented 4 months ago

The issue does indeed go away if dependency.analysis.autoapply=false is omitted. It happens because the plugin configures itself for Android projects inside an afterEvaluate block. I think this may not be necessary. I validated that if I remove the afterEvaluate, this error doesn't occur anymore.