-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
I tried using gradle-git-properties Gradle plugin to set a git commit as an image tag. Following their plugin doc,
plugins {
id 'com.gorylenko.gradle-git-properties' version '2.2.3'
id 'com.google.cloud.tools.jib' version '2.5.0'
id 'java'
}
gitProperties {
extProperty = 'gitProps' // git properties will be put in a map at project.ext.gitProps
}
// make sure the generateGitProperties task always executes (even when git.properties is not changed)
generateGitProperties.outputs.upToDateWhen { false }
// make sure generateGitProperties task to execute before accessing generated properties
task printGitProperties(dependsOn: 'generateGitProperties') {
doLast {
println "git.commit.id.abbrev=" + project.ext.gitProps['git.commit.id.abbrev']
}
}Running ./gradlew printGitProperties works as documented.
The doc also shows an example using Groovy GString lazy evaluation.
jar {
manifest {
attributes(
// Use GString lazy evaluation to delay until git properties are populated
'Build-Revision': "${-> project.ext.gitProps['git.commit.id.abbrev']}"
// OTOH, the following code fails with "Cannot get property 'gitProps' on extra properties extension as it does not exist"
//'Build-Revision': project.ext.gitProps['git.commit.id.abbrev']
)
}
}I confirm ./gradlew jar works and the MANIFEST.MF in the JAR contains the Build-Revision attribute.
However, we still can't use GString lazy evaluation with most of the Jib properties. It fails with "Cannot get property 'gitProps' on extra properties extension as it does not exist."
I think it makes sense to convert jib.to.image and jib.to.tags to Property<String> and SetProperty<String>. Property<String> has two .set() methods, one with signature .set(String) and the other with .set(Provider<String>), which I think will allow configuring these values lazily.