Home > Enterprise >  Is there a way to extend or create different jib configuration in gradle.build file
Is there a way to extend or create different jib configuration in gradle.build file

Time:09-17

I am using the jib plugin to build my docker image for my springboot app. However, I want to have a new task in my build file which will call a different build jib task.

The reason for this is that depending on the task I create in gradle, I want to set different JVM values for different tasks.

Existing implementation when using gradle jib plugin.

Example:

plugins {
    id 'com.google.cloud.tools.jib' version '2.0.0'
}


jib {
    container {
        creationTime = "USE_CURRENT_TIMESTAMP"
        jvmFlags = ['flag a']
    }
}

// Extend jib task and set different flags.
jibWithDifferentVMFlags {
    container {
        creationTime = "USE_CURRENT_TIMESTAMP"
        jvmFlags = ['different flags']
    }
}

After this, I can choose which task to build my image with example:

./gradlew jib
or
./gradlew jibWithDifferentVMFlags

The aim is to have thow options, the default and custom as above.

Im not a gradle expert but any help would be highly appreciated or any different approach is welcome. thanks

CodePudding user response:

You could use a property to simulate profiles.

plugins {
    id 'com.google.cloud.tools.jib' version '3.1.4'
}


jib {
    container {
        creationTime = "USE_CURRENT_TIMESTAMP"
        jvmFlags = ['flag a']
        if (project.hasProperty('foo')) {
            jvmFlags = ['different flags']
        }
    }
}

To do a FOO build:

$ ./gradlew jib -Pfoo

Also, use the latest Jib 3.1.4 (as of now).

  • Related