Convert Gradle config parameters (such as jib.container.labels) to use lazy evaluation
See original GitHub issueJust like there was an issue to make the jib.to.tags and jib.to.auth to be lazyly evaluated I would need to have the container.labels do the same. Even the reason is the same. I use com.gorylenko.gradle-git-properties Gradle plugin and would like to reuse its properties to add labels to my images. Something like that:
jib {
container {
labels = [
'org.label-schema.vcs-url': project.ext.gitProps['git.remote.origin.url'],
'org.label-schema.vcs-branch': project.ext.gitProps['git.branch'],
'org.label-schema.vcs-ref': project.ext.gitProps['git.commit.id.abbrev']
]
}
}
In our case I would make that configuration global and add this snipped to our custom gradle wrapper init script.
I did try something like this:
jib
container {
labels = [
...
'org.label-schema.vcs-ref': "${-> project.ext.gitProps['git.commit.id.abbrev']}"
]
}
}
But this errored out with this message:
> class org.codehaus.groovy.runtime.GStringImpl cannot be cast to class java.lang.String (org.codehaus.groovy.runtime.GStringImpl is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @47c62251; java.lang.String is in module java.base of loader 'bootstrap')
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top GitHub Comments
@remy-tiitre @ChristianCiach @NaitYoussef Jib 3.1.1 is released with this support. Let us know if it doesn’t work.
@NaitYoussef thanks for your interest!
As noted in https://github.com/GoogleContainerTools/jib/issues/3094#issuecomment-788064416,
the way we decided to expose Gradle properties is to use
Property<?>
like this. That is, no setters but a getter will directly expose aProperty<?>
.This GitHub issue is about
jib.container.labels
, so my guess is that this propertylabels
should be changed to be of typeMapProperty
. This may not be fully backward-compatible, but I think should be fine most of the time.