0

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?

Rolf W.
  • 1,379
  • 1
  • 15
  • 25
  • 1
    Regarding your second approach, you must use `toString()` for `project.version`, because it is defined as `Object`. – Lukas Körfer Aug 28 '19 at 12:41
  • Indeed! That makes sense then, but it still doesn't compile: `Type mismatch: inferred type is (Any?) -> String! but (() -> TypeVariable(T)!)! was expected`. I'm not that familiar with Kotlin, but in Java such a lamba would compile now that it returns String if I'm not mistaken. What am I missing? – Rolf W. Aug 28 '19 at 13:47

0 Answers0