I'm trying to use the Jgitver Gradle Plugin together with the BuildConfig Gradle Plugin but I'm not getting the version in the generated BuildConfig class. Instead I get Unspecified
.
This is because of ordering and so far I wasn't able to get the ordering right. Jgitver doesn't use a task and sets the project version in the afterEvaluate
phase, as can be seen here.
The way to go seems to be lazy evaluation as described here. I couldn't figure out how to do this with the Kotlin DSL though.
Code example
plugins {
java
id("de.fuerstenau.buildconfig") version "1.1.8"
id("fr.brouillard.oss.gradle.jgitver") version "0.9.1"
}
configure<BuildConfigExtension> {
afterEvaluate { /* type mismatch for provider { project.version } if I remove this block
version = provider { project.version }
clsName = "BuildConfig" /* The name of the class that contains the build config */
packageName = "com.somegroup"
charset = "UTF-8"
}
}
I also tried another approach val lazyVersion: Provider<String> = providers.provider { () -> project.version }
and then use lazyVersion
but that doesn't compile: Type mismatch: inferred type is Any! but String was expected
.
Another thing I tried is to add afterEvaluate to the configure closure as described in this Jgitver issue, but it doesn't work for me. Probably because the order in which afterEvaluate closures are executed is undefined.
Question
What's the recommended way to get the value of project.version
after it was set by Jgitver in afterEvaluate? And what would be the correct syntax?