Skip to content
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

Convert Gradle config parameters (such as jib.to.image and jib.to.tags) to use Property type #2727

Closed
chanseokoh opened this issue Aug 25, 2020 · 3 comments · Fixed by #2739
Assignees
Milestone

Comments

@chanseokoh
Copy link
Member

chanseokoh commented Aug 25, 2020

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.

@loosebazooka
Copy link
Member

Yeah I don't think you can use GString lazy eval, but you can use Provider<String> to basically do the same thing?

@chanseokoh chanseokoh added this to the v2.6.0 milestone Aug 26, 2020
@chanseokoh
Copy link
Member Author

convert jib.to.image and jib.to.tags to Property<String> and SetProperty<String>.

Much like we currently use Property<String> for jib.containerizingMode. (On hindsight, I think I just used Property<String> instead of String for it without thinking much only after seeing there existed Property<Boolean>.)

private final Property<String> containerizingMode;

@loosebazooka
Copy link
Member

loosebazooka commented Sep 29, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants