ReactiveCircus / app-versioning

A Gradle Plugin for lazily generating Android app's versionCode & versionName from Git tags.
Apache License 2.0
205 stars 3 forks source link

Cannot fingerprint input property 'kotlinVersionCodeCustomizer': value '(GitTag, ProviderFactory, VariantInfo) -> kotlin.Int' cannot be serialized. #33

Closed mr3y-the-programmer closed 1 year ago

mr3y-the-programmer commented 1 year ago

I'm getting the following error when running ./gradlew generateAppVersionInfoFor<Variant> with gradle configuration cache disabled.

> Cannot fingerprint input property 'kotlinVersionCodeCustomizer': value '(io.github.reactivecircus.appversioning.GitTag, org.gradle.api.provider.ProviderFactory, io.github.reactivecircus.appversioning.VariantInfo) -> kotlin.Int' cannot be serialized.

And I'm getting the following 2 errors when running ./gradlew generateAppVersionInfoFor<Variant> with gradle configuration cache enabled. the first error is the aforementioned one, and the the second one is:

1 problem was found storing the configuration cache.
- Task `:app:generateAppVersionInfoFor<Variant>` of type `io.github.reactivecircus.appversioning.tasks.GenerateAppVersionInfo`: cannot serialize Gradle script object references as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.2.1/userguide/configuration_cache.html#config_cache:requirements:disallowed_types

I thought that configuration cache problems were addressed at #24, but even when the configuration cache is disabled, the build still fails with the first error above.

Steps to reproduce: app-versioning: 1.3.1 Gradle: 8.2.1 AGP: 8.1.0 appVersioning extension configuration in my app's build.gradle.kts:

appVersioning {
    overrideVersionCode { _, _, _ ->
        extensions.getByType<ApplicationExtension>().defaultConfig.versionCode!! + 1
    }
}

Run generateAppVersionInfo for any variant, for example debug: ./gradlew generateAppVersionInfoForDebug

Additional Context: I reproduced it on my side project https://github.com/mr3y-the-programmer/Ludi as I was trying to automate the release process for it.

ychescale9 commented 1 year ago

I think you want to avoid referencing anything external such as extensions within the overrideVersionCode lambda.

Also when using this plugin versionCode shouldn't be set in android.defaultConfig which is evaluated eagerly and thus defeats the purpose of computing the version code lazily.

The idea is the result of the overrideVersionCode lambda is the single source of truth and the 3 parameters of the lambda should provide what you need to compute the versionCode.

mr3y-the-programmer commented 1 year ago

My Use case is increasing the versionCode property by 1 on each release, this is why I used extensions to get the current versionCode but this is not strictly required, if that defeats the purpose of computing the version code lazily, I can avoid it and I think I will compute the versionCode using only the 3 parameters as you mentioned Thanks.

mr3y-the-programmer commented 1 year ago

Follow up: After computing versionCode lazily, running generateAppVersionInfoFor<Variant> completes successfully without errors.

VitaSokolova commented 11 months ago

Could you show a code snippet how did you "compute versionCode lazily"?