GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.58k stars 1.43k forks source link

Missing buildplan on gradle plugin jib extension #4150

Closed muhrifqii closed 5 months ago

muhrifqii commented 9 months ago

Environment:

Description of the issue: When we are using the convention to utilize the setting on each module, we cannot set jib.container.format because unresolved reference of com.google.cloud.tools.jib.api.buildplan, causing ImageFormat.OCI or ImageFormat.Docker cannot be customized

Expected behavior: can set the jib.container.format into enum values of ImageFormat.OCI

Steps to reproduce:

  1. Setup a multiple module project with gradle kts
  2. Create a build logic kotlin-dsl
  3. Use JibExtension
  4. set jib.container.format

jib-gradle-plugin Configuration:

import com.google.cloud.tools.jib.gradle.JibExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

fun Project.configureJib() {
    jib {
        to {
            image = "my-image:version"
            tags = setOf("foo", "bar")
        }
        container.format = com.google.cloud.tools.jib.api.buildplan.ImageFormat.OCI
    }
}

internal fun Project.jib(action: JibExtension.() -> Unit) = extensions.configure(action)

Log output: Cannot access class 'com.google.cloud.tools.jib.api.buildplan.ImageFormat'. Check your module classpath for missing or conflicting dependencies

Additional Information:

chanseokoh commented 9 months ago

The type of jib.container.format is String. Set either 'Docker' or 'OCI'. The BuildPlan is a separate concept, and the Jib plugin configuration is an abstraction on top of it.

https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#container-closure

Property Type Default Description
format String Docker Use OCI to build an OCI container image.
johnburbridge commented 8 months ago

Environment: Jib version: 3.4.0 Build tool: Gradle 8.5 using kotlin script OS: MacOs Sonoma 4.2 / Ubuntu 22.04.3 IDE: IntelliJ IDEA 2023.3.2 (Ultimate Edition) Build #IU-233.13135.103, built on December 19, 2023

The type of jib.container.format is String. Set either 'Docker' or 'OCI'. The BuildPlan is a separate concept, and the Jib plugin configuration is an abstraction on top of it.

I have the same experience as @muhrifqii. I'm also trying to do this in a gradle convention plugin.

Attempting to set it as a string will result in a type mismatch.

image

And if I try doing the same in a convention plugin then I get an unresolved reference for buildplan.

image

Oddly enough, I don't run into the unresolved buildplan package if setting the format in a regular build.gradle.kts script (as opposed to a convention plugin). But then I'm only able to set the value directly using the enum of ImageFormat.Docker (or OCI). Trying to set it as a String results in a type mismatch either way.

Perhaps odder yet is that I'm able to get Jib to work if I leave the format unset (default configuration which is ImageFormat.Docker)

chanseokoh commented 7 months ago

I wonder if it is just IntelliJ that incorrectly reports type mismatch inside the IDE. I would be surprised if running Gradle on the command-line actually fails.

In any case, you can try directly calling setFormat('Docker') inside container.

alicejli commented 5 months ago

Closing this as it seems there is a viable workaround. Please reopen with more context if this is still an issue.