Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

Version 3.0.0 breaks lazy configuration #858

Closed ychescale9 closed 3 years ago

ychescale9 commented 4 years ago

Describe the bug

The latest version of the plugin seems to break lazy task configuration by eagerly evaluating the versionCode during configuration.

This breaks projects which have migrated to setting versionCode with the new onVariantProperties API instead of setting it directly in defaultConfig, as the versionCode won't be available for querying during configuration.

How To Reproduce

Instead of setting versionCode directly in defaultConfig:

android {
  defaultConfig {
    ...
    versionCode 1
  }
}

Set the versionCode lazily as shown in this AGP recipe.

Running ./gradlew help will fails with something like:

java.io.FileNotFoundException: path/to/project/app/build/outputs/app_versioning/prodRelease/version_code.txt (No such file or directory)

where version_code.txt is the @OutputFile of the custom task which is wired up with the versionCode property of the VariantOutput.

Versions

Is it possible to avoid evaluating the versionCodes during configuration? Maybe something along this line?

val staticVersionCodes = project.objects.listProperty<Int>().apply {
  outputs.forEach {
    add(it.versionCode)
  }
}

Thanks!

SUPERCILEX commented 4 years ago

Dang, thanks for the thorough investigation. The issue is that if I lazily evaluate the property, then I end up in a recursive loop because I'll be getting the value I myself set: https://github.com/Triple-T/gradle-play-publisher/blob/1a009c0c8ad036c879d4c7bf1c1c389006838e3a/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt#L352

So the idea is to get the value of the property before I overwrite it. I'm guessing forUseAtConfigurationTime would fix it, but that means I'll be forcing your task to run even if you don't use the auto resolution feature. What I really want is a way to get the backing value of the property.

TL;DR: need to investigate the proper solution.

ychescale9 commented 4 years ago

Yeah I've definitely run into this kind of chicken and egg problems a lot with task wiring in the lazy configuration era. I wish I could be of more help but right now I need to learn more about how the tasks are all wired up etc.

Here's the custom plugin I wrote that doesn't play well with with GPP. And as you said GPP is forcing the generateAppVersionInfo task to run during configuration.

I'll do some more digging.

SUPERCILEX commented 3 years ago

I gave up trying to fix the chicken and egg problem. The best I came up with is to only be broken if you use ResolutionStrategy.AUTO which seems reasonable. If you're setting your own version code, you probably shouldn't be using ResolutionStrategy.AUTO.

ychescale9 commented 3 years ago

Interestingly, everything seems to work without specifying ResolutionStrategy with 3.4.0-agp7.0 and latest AGP (7.0.0-alpha14) 😄

SUPERCILEX commented 3 years ago

Awesome! The default resolution strategy is FAIL so basically it should work by default unless you've manually configured it to auto.