-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Building versionName/versionCode from data external (to lambda) #14
Comments
This is tricky. The If you try to get the value of The only workaround I can think of right now is: class WrapperPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.plugins.withType<AppPlugin> {
val wrapperExtension = project.extensions.create("wrapper", WrapperExtension::class.java)
project.plugins.apply(AppVersioningPlugin::class.java)
val extension = project.extensions.getByType(AppVersioningExtension::class.java)
val myFilter = AtomicReference<String>(null)
project.afterEvaluate {
myFilter.set(wrapperExtension.myFilter.get())
}
extension.overrideVersionName { gitTag, providerFactory, variantInfo ->
myFilter.get()
}
}
}
} I could change the plugin to add The other option is to add a |
Thanks for the input. It seems even the
cannot be done (it triggers I understand that this is probably a niche use case so it makes sense to not pollute the API with these specific requirements. However, I think it the |
Hmm, I was able to do get this to work locally. How are you defining your This is how I defined it: open class WrapperExtension internal constructor(objects: ObjectFactory) {
val myFilter = objects.property<String>().convention(null)
} |
This is how my extension is defined:
perhaps the |
That doesn't seem to make a difference. Unless you're not actually setting Here are all the changes I have locally: In dependencies {
...
implementation("io.github.reactivecircus.appversioning:app-versioning-gradle-plugin:0.8.1")
}
gradlePlugin {
plugins {
register("wrapper") {
id = "wrapper-plugin"
implementationClass = "io.github.reactivecircus.streamlined.WrapperPlugin"
}
}
} In my package io.github.reactivecircus.streamlined
import com.android.build.gradle.internal.plugins.AppPlugin
import io.github.reactivecircus.appversioning.AppVersioningExtension
import io.github.reactivecircus.appversioning.AppVersioningPlugin
import java.util.concurrent.atomic.AtomicReference
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.withType
class WrapperPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.plugins.withType<AppPlugin> {
val wrapperExtension = project.extensions.create("wrapper", WrapperExtension::class.java)
project.plugins.apply(AppVersioningPlugin::class.java)
val extension = project.extensions.getByType(AppVersioningExtension::class.java)
val myFilter = AtomicReference<String>(null)
project.afterEvaluate {
myFilter.set(wrapperExtension.myFilter.get())
}
extension.overrideVersionName { gitTag, providerFactory, variantInfo ->
myFilter.get()
}
}
}
}
open class WrapperExtension internal constructor(objects: ObjectFactory) {
val myFilter = objects.property<String>().convention(null)
} Finally in the plugins {
`wrapper-plugin`
id("com.android.application")
kotlin("android")
...
}
wrapper {
myFilter.set("0-9]*.[0-9]*.[0-9]*")
}
... Running
|
Thanks a lot for looking into this. I'll try to replicate what you did and figure out why it fails on my side. |
I guess this is more of a question.. How would it be possible to customize the versionName/versionCode using data not provided as input to the lambda (GitTag, ProviderFactory, VariantInfo)?
Context: I'm building an opinionated wrapper plugin around
app-versioning
and would like to declare my own plugin extension that app projects populate. Those extension properties would be used in theoverrideVersionName
lambda to calculate the version name.If I try to use my custom extension property in the
overrideVersionName
lambda like this:I get the error:
Property 'kotlinVersionNameCustomizer' with value '(io.github.reactivecircus.appversioning.GitTag, org.gradle.api.provider.ProviderFactory, io.github.reactivecircus.appversioning.VariantInfo) -> kotlin.String' cannot be serialized
Am I missing something obvious here?
Basically, I guess I would like "myFilter" to be a part of the input to the
GenerateAppVersionInfo
task.The text was updated successfully, but these errors were encountered: