Skip to content

Commit f4f43be

Browse files
SUPERCILEXbhurling
authored andcommitted
Fix compatibility issues on old Gradle versions that don't know how to unwrap Providers (#443)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent f686d08 commit f4f43be

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.github.triplet.gradle.play.internal.ACCOUNT_CONFIG
77
import com.github.triplet.gradle.play.internal.AccountConfig
88
import com.github.triplet.gradle.play.internal.PLAY_PATH
99
import com.github.triplet.gradle.play.internal.configure
10+
import com.github.triplet.gradle.play.internal.dependsOnCompat
1011
import com.github.triplet.gradle.play.internal.get
1112
import com.github.triplet.gradle.play.internal.newTask
1213
import com.github.triplet.gradle.play.internal.set
@@ -107,7 +108,7 @@ class PlayPublisherPlugin : Plugin<Project> {
107108
"bootstrap${variantName}PlayResources",
108109
"Downloads the Play Store listing metadata for $variantName."
109110
) { init() }
110-
bootstrapAllTask.configure { dependsOn(bootstrapTask) }
111+
bootstrapAllTask.configure { dependsOnCompat(bootstrapTask) }
111112

112113
val playResourcesTask = project.newTask<GenerateResources>(
113114
"generate${variantName}PlayResources",
@@ -124,12 +125,12 @@ class PlayPublisherPlugin : Plugin<Project> {
124125
init()
125126
resDir = playResourcesTask.get().resDir
126127

127-
dependsOn(playResourcesTask)
128+
dependsOnCompat(playResourcesTask)
128129
}
129-
publishListingAllTask.configure { dependsOn(publishListingTask) }
130+
publishListingAllTask.configure { dependsOnCompat(publishListingTask) }
130131
// TODO Remove in v3.0
131132
project.newTask("publishListing$variantName", "", null) {
132-
dependsOn(publishListingTask)
133+
dependsOnCompat(publishListingTask)
133134
doFirst { logger.warn("$name is deprecated, use ${publishListingTask.get().name} instead") }
134135
}
135136

@@ -140,9 +141,9 @@ class PlayPublisherPlugin : Plugin<Project> {
140141
init()
141142
resDir = playResourcesTask.get().resDir
142143

143-
dependsOn(playResourcesTask)
144+
dependsOnCompat(playResourcesTask)
144145
}
145-
publishProductsAllTask.configure { dependsOn(publishProductsTask) }
146+
publishProductsAllTask.configure { dependsOnCompat(publishProductsTask) }
146147

147148
val processPackageMetadata = project.newTask<ProcessPackageMetadata>(
148149
"process${variantName}Metadata",
@@ -153,7 +154,7 @@ class PlayPublisherPlugin : Plugin<Project> {
153154
checkManifestProvider.configure { dependsOn(processPackageMetadata) }
154155
} catch (e: NoSuchMethodError) {
155156
@Suppress("DEPRECATION")
156-
checkManifest.dependsOn(processPackageMetadata)
157+
checkManifest.dependsOnCompat(processPackageMetadata)
157158
}
158159

159160
val publishApkTask = project.newTask<PublishApk>(
@@ -163,8 +164,8 @@ class PlayPublisherPlugin : Plugin<Project> {
163164
init()
164165
resDir = playResourcesTask.get().resDir
165166

166-
dependsOn(processPackageMetadata)
167-
dependsOn(playResourcesTask)
167+
dependsOnCompat(processPackageMetadata)
168+
dependsOnCompat(playResourcesTask)
168169
try {
169170
variant.assembleProvider
170171
} catch (e: NoSuchMethodError) {
@@ -173,10 +174,10 @@ class PlayPublisherPlugin : Plugin<Project> {
173174
}?.let { dependsOn(it) }
174175
?: logger.warn("Assemble task not found. Publishing APKs may not work.")
175176
}
176-
publishApkAllTask.configure { dependsOn(publishApkTask) }
177+
publishApkAllTask.configure { dependsOnCompat(publishApkTask) }
177178
// TODO Remove in v3.0
178179
project.newTask("publishApk$variantName", "", null) {
179-
dependsOn(publishApkTask)
180+
dependsOnCompat(publishApkTask)
180181
doFirst { logger.warn("$name is deprecated, use ${publishApkTask.get().name} instead") }
181182
}
182183

@@ -187,8 +188,8 @@ class PlayPublisherPlugin : Plugin<Project> {
187188
init()
188189
resDir = playResourcesTask.get().resDir
189190

190-
dependsOn(processPackageMetadata)
191-
dependsOn(playResourcesTask)
191+
dependsOnCompat(processPackageMetadata)
192+
dependsOnCompat(playResourcesTask)
192193
// Remove hack when AGP 3.2 reaches stable channel
193194
project.tasks.findByName(
194195
(variant as InstallableVariantImpl).variantData.getTaskName("bundle", ""))
@@ -197,7 +198,7 @@ class PlayPublisherPlugin : Plugin<Project> {
197198
"'com.android.tools.build:gradle' v3.2+. " +
198199
"Publishing App Bundles may not work.")
199200
}
200-
publishBundleAllTask.configure { dependsOn(publishBundleTask) }
201+
publishBundleAllTask.configure { dependsOnCompat(publishBundleTask) }
201202

202203
val promoteReleaseTask = project.newTask<PromoteRelease>(
203204
"promote${variantName}Artifact",
@@ -206,22 +207,22 @@ class PlayPublisherPlugin : Plugin<Project> {
206207
init()
207208
resDir = playResourcesTask.get().resDir
208209

209-
dependsOn(playResourcesTask)
210+
dependsOnCompat(playResourcesTask)
210211
}
211-
promoteReleaseAllTask.configure { dependsOn(promoteReleaseTask) }
212+
promoteReleaseAllTask.configure { dependsOnCompat(promoteReleaseTask) }
212213

213214
val publishTask = project.newTask<LifecycleHelperTask>(
214215
"publish$variantName",
215216
"Uploads APK or App Bundle and all Play Store metadata for $variantName."
216217
) {
217218
this.extension = extension
218219

219-
dependsOn(
220+
dependsOnCompat(
220221
if (extension.defaultToAppBundles) publishBundleTask else publishApkTask)
221-
dependsOn(publishListingTask)
222-
dependsOn(publishProductsTask)
222+
dependsOnCompat(publishListingTask)
223+
dependsOnCompat(publishProductsTask)
223224
}
224-
publishAllTask.configure { dependsOn(publishTask) }
225+
publishAllTask.configure { dependsOnCompat(publishTask) }
225226
}
226227

227228
project.afterEvaluate {

plugin/src/main/kotlin/com/github/triplet/gradle/play/internal/Plugins.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ internal fun <T : Task> Provider<T>.configure(block: T.() -> Unit) {
5353
}
5454
}
5555

56+
internal fun Task.dependsOnCompat(lazy: Provider<out Task>) =
57+
dependsOn(if (isConfigurationAvoidanceSupported) lazy else lazy.get())
58+
5659
internal operator fun ProductFlavor.get(name: String) = extras[name]
5760

5861
internal operator fun ProductFlavor.set(name: String, value: Any?) {

plugin/src/test/kotlin/com/github/triplet/gradle/play/CompatibilityTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CompatibilityTest(
8989
.withPluginClasspath()
9090
.withGradleDistribution(URI(gradleDist))
9191
.withProjectDir(testProject.projectDir)
92-
.withArguments("tasks")
92+
.withArguments("checkReleaseManifest")
9393
.build()
9494
GradleRunner.create()
9595
.withPluginClasspath()

0 commit comments

Comments
 (0)