cianru / huawei-appgallery-publish-gradle-plugin

Huawei AppGallery Publish Gradle Plugin allows you to publish the android release build file (*.apk or *.aab) to the Huawei AppGallery store
Apache License 2.0
111 stars 20 forks source link

Broken Task Configuration Avoidance #46

Closed rmarma closed 1 year ago

rmarma commented 1 year ago

Problem

To establish a soft relationship between tasks, the plugin uses the whenTaskAdded method. This breaks the Task Configuration Avoidance. Scan for task ./gradlew :app:help: plugin-task-configuration-avoidance-problem

Quick fix

Replace whenTaskAdded with configureEach. But we are still losing "laziness" for the publishHuaweiAppGallery task in this line:

publishTask.get().mustRunAfter(this)

Solution

We can be sure that the project contains assemble and bundle tasks, because the plugin is only used together with com.android.application:

project.plugins.withType<AppPlugin> {
    configureHuaweiPublish(project)
}

Therefore, we can establish the relationship between the tasks as follows:

project.tasks.register<HuaweiPublishTask>(publishTaskName, variant).configure {
    setMustRunAfter(
        setOf(
            project.tasks.named("assemble$variantName"),
            project.tasks.named("bundle$variantName"),
        )
    )
}

Need testing!

rmarma commented 1 year ago

https://github.com/rmarma/huawei-appgallery-publish-gradle-plugin/pull/1

cosic commented 1 year ago

@rmarma Thank you for fix the configuration cache issue. Could you create Pull Request on snapshot-1.3.6 branch on this repository?

rmarma commented 1 year ago

@cosic, done https://github.com/cianru/huawei-appgallery-publish-gradle-plugin/pull/47

cosic commented 1 year ago

@rmarma Thank you. I'm going to release it in a few days. You can try changes at 1.3.6-SNAPSHOT version now.

rmarma commented 1 year ago

@cosic, It works, but only on JDK 18: plugin-task-configuration-avoidance-result

On JDK 17/11 get error:

> Could not resolve all files for configuration ':classpath'.
   > Could not resolve ru.cian:huawei-publish-gradle-plugin:1.3.6-SNAPSHOT.
     Required by:
         project :
      > No matching variant of ru.cian:huawei-publish-gradle-plugin:1.3.6-SNAPSHOT:20230429.205109-1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 17, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.1.1' but:
          - Variant 'apiElements' capability ru.cian:huawei-publish-gradle-plugin:1.3.6-SNAPSHOT declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 18 and the consumer needed a component for use during runtime, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')
          - Variant 'runtimeElements' capability ru.cian:huawei-publish-gradle-plugin:1.3.6-SNAPSHOT declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 18 and the consumer needed a component, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1.1')

1.3.6-SNAPSHOT:20230429.205109-1 compiled with JDK 18?

cosic commented 1 year ago

1.3.6-SNAPSHOT:20230429.205109-1 compiled with JDK 18?

Yes, it compiled with JDK 18. I have been prepared new version for AGP 8+. But it seems a better way release configuration cache on JDK 11-17 and upto JDK 18 at next release.

cosic commented 1 year ago

@rmarma So, I've published 2 versions:

rmarma commented 1 year ago

@cosic, thanks)

Why JDK 18? AFAIK, AGP 8 requires JDK17.

cosic commented 1 year ago

@rmarma Actualy you are right. I shoult build it with JDK 17.

rmarma commented 1 year ago

@cosic, ok.

1.3.6 - JDK11+ 1.4.0 - JDK17+

The problem is solved, we can close this issue.