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

Fix: Task Configuration Avoidance #1

Merged
merged 1 commit into from
May 25, 2023

Conversation

rmarma
Copy link
Owner

@rmarma rmarma commented Apr 27, 2023

Problem

To establish a soft relationship between tasks, the plugin uses the whenTaskAdded method. This breaks the Task Configuration Avoidance.
See 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!

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