From d81433b67b32f4c5128ad9b2ebb22982e905ddf4 Mon Sep 17 00:00:00 2001 From: Aleksandr Mirko Date: Sat, 9 Dec 2023 02:15:38 +0300 Subject: [PATCH] Issue #4: mustRunAfter assemle and bundle task without affect on configuration cache --- README.md | 2 +- gradle/libs.versions.toml | 2 +- .../publish/RustorePublishExtension.kt | 27 +--------- .../rustore/publish/RustorePublishPlugin.kt | 50 ++++++------------- sample-kotlin/build.gradle.kts | 3 -- settings.gradle.kts | 2 +- 6 files changed, 20 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 63ba781..9d33615 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # RuStore Publishing -![Version](https://img.shields.io/badge/GradlePortal-0.2.1-green.svg) +![Version](https://img.shields.io/badge/GradlePortal-0.2.2-green.svg) ![Version](https://img.shields.io/badge/Gradle-7.*-pink.svg) [![License](https://img.shields.io/github/license/srs/gradle-node-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 46b63ce..1642fb1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ buildToolsVersion = "33.0.0" kotlin = "1.8.0" junitJupiter = "5.7.0" androidGradlePlugin = "7.4.2" -sampleRustorePlugin = "0.2.0-SNAPSHOT" +sampleRustorePlugin = "0.2.2-SNAPSHOT" [libraries] appcompat = "androidx.appcompat:appcompat:1.3.1" diff --git a/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishExtension.kt b/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishExtension.kt index d041313..227f7fa 100644 --- a/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishExtension.kt +++ b/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishExtension.kt @@ -33,7 +33,6 @@ class RustorePublishExtensionConfig( var releaseTime: String? = null var releasePhase: ReleasePhaseExtension? = null var releaseNotes: List? = null - var pluginSettings: PluginSettings = PluginSettings() init { if (name.isBlank()) { @@ -41,11 +40,6 @@ class RustorePublishExtensionConfig( } } - fun pluginSettings(closure: Closure): PluginSettings { - pluginSettings = PluginSettings() - project.configure(pluginSettings, closure) - return pluginSettings - } fun releasePhase(closure: Closure): ReleasePhaseExtension { releasePhase = ReleasePhaseExtension() project.configure(releasePhase!!, closure) @@ -61,8 +55,7 @@ class RustorePublishExtensionConfig( "buildFile='$buildFile', " + "releaseTime='$releaseTime', " + "releasePhase='$releasePhase', " + - "releaseNotes='$releaseNotes', " + - "pluginSettings='$pluginSettings'" + + "releaseNotes='$releaseNotes'" + ")" } } @@ -104,24 +97,6 @@ open class ReleaseNote { } } -open class PluginSettings { - - var applyConfigureOptimization: Boolean = true - - constructor() { - // nothing; - } - constructor(applyConfigureOptimization: Boolean) { - this.applyConfigureOptimization = applyConfigureOptimization - } - - override fun toString(): String { - return "PluginSettings(" + - "applyConfigureOptimization='$applyConfigureOptimization'" + - ")" - } -} - enum class BuildFormat(val fileExtension: String) { APK("apk"), AAB("aab"), diff --git a/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishPlugin.kt b/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishPlugin.kt index 5dd6a9e..5a66bbf 100644 --- a/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishPlugin.kt +++ b/plugin/src/main/kotlin/ru/cian/rustore/publish/RustorePublishPlugin.kt @@ -14,8 +14,6 @@ import org.gradle.kotlin.dsl.withType class RustorePublishPlugin : Plugin { - private val tasksMustRunAfter = mutableMapOf() - override fun apply(project: Project) { project.plugins.withType { configureRustorePublish(project) @@ -44,45 +42,29 @@ class RustorePublishPlugin : Plugin { val publishTaskName = "${RustorePublishTask.TASK_NAME}$variantName" val publishTask = project.tasks.register(publishTaskName, variant) val extension = rustorePublishExtension.instances.find { it.name.equals(variant.name, ignoreCase = true) } - val applyConfigureOptimization = extension?.pluginSettings?.applyConfigureOptimization - tasksMustRunAfter.put(publishTaskName, "assemble$variantName") - tasksMustRunAfter.put(publishTaskName, "bundle$variantName") - sheduleTasksOrder(applyConfigureOptimization, publishTask, project, variantName) + scheduleTasksOrder(publishTask, project, variantName) } - private fun sheduleTasksOrder( - applyConfigureOptimization: Boolean?, + private fun scheduleTasksOrder( publishTask: TaskProvider, project: Project, variantName: String ) { - if (applyConfigureOptimization == true) { - publishTask.configure { - // println("--> RustorePublishTask registered: ($publishTaskName)") - // project.tasks.forEach { - // println("--> (1): ${it.name}") - // } - // setMustRunAfter( - // setOf( - //// project.tasks.named("clean"), - // project.tasks.named("assemble$variantName"), - // project.tasks.named("bundle$variantName"), - // ) - // ) - if (project.tasks.findByName("assemble$variantName") != null) { - setMustRunAfter(setOf(project.tasks.named("assemble$variantName"))) - } - if (project.tasks.findByName("bundle$variantName") != null) { - setMustRunAfter(setOf(project.tasks.named("bundle$variantName"))) - } - } - } else { - project.tasks.whenTaskAdded { - if (this.name == "assemble$variantName" || this.name == "bundle$variantName") { - publishTask.get().mustRunAfter(this) - } - } + project.gradle.projectsEvaluated { + mustRunAfter(project, publishTask, "assemble$variantName") + mustRunAfter(project, publishTask, "bundle$variantName") + } + } + + private fun mustRunAfter( + project: Project, + publishTask: TaskProvider, + taskBeforeName: String, + ) { + if (project.tasks.findByName(taskBeforeName) != null) { + val assembleTask = project.tasks.named(taskBeforeName).get() + publishTask.get().mustRunAfter(assembleTask) } } } diff --git a/sample-kotlin/build.gradle.kts b/sample-kotlin/build.gradle.kts index a0bc14c..fe36b0b 100644 --- a/sample-kotlin/build.gradle.kts +++ b/sample-kotlin/build.gradle.kts @@ -14,9 +14,6 @@ rustorePublish { filePath = "$projectDir/release-notes-ru.txt" ), ) - pluginSettings = ru.cian.rustore.publish.PluginSettings( - applyConfigureOptimization = true - ) } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 0d7f3fe..9296495 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,7 @@ include( pluginManagement { - val rustorePublish = "0.2.0-SNAPSHOT" + val rustorePublish = "0.2.2-SNAPSHOT" resolutionStrategy { eachPlugin {