Skip to content

feat: Add maven jib build support#596

Merged
joaopapereira merged 18 commits into
carvel-dev:developfrom
BulldromeQ:jib-support
Jun 10, 2026
Merged

feat: Add maven jib build support#596
joaopapereira merged 18 commits into
carvel-dev:developfrom
BulldromeQ:jib-support

Conversation

@BulldromeQ

@BulldromeQ BulldromeQ commented May 27, 2026

Copy link
Copy Markdown

Summary

This pull request introduces support for Maven Jib builds, upstreaming the changes developed in the vishrantgupta/kbld fork.

The changes include:

  • Adding structure to support Maven Jib build (pkg/kbld/builder/maven/jib.go).
  • Updating image building configs to allow Jib integrations.
  • Allowing insecure registries with Jib builder.
  • Adding a sample app and end-to-end tests for simple-app-build-local-mvn.

Vishrant Gupta added 3 commits May 27, 2026 12:58
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
- Add missing copyright header to jib.go
- Update errcheck exclude for PrefixWriter
- Handle returned errors in git_test.go

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Fix line length limits (under 80 characters) across docker, jib, and built images.
- Add package-level comment and document exported fields/functions in jib and config.
- Fix redundant import aliases and import shadowing of package name maven.
- Remove unused global regexp variable ImageID.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Remove extra empty lines at the start of blocks in jib.go and built.go
- Replace unnecessary fmt.Errorf with errors.New in jib.go
- Add missing exported comment to NewBuiltImage in built.go

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Create a `BuildersOpts` struct to group the builder dependencies.
- Update `NewBuiltImage` in built.go to accept `BuildersOpts` instead of
  10 individual parameters, resolving the argument-limit (max 8) linter error.
- Update `Factory.New` in factory.go to construct and pass `BuildersOpts`.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Wrap the function signature for `Jib.Run` to keep the line length
  below the 80 characters limit enforced by the revive linter.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class Maven/Jib build support to kbld so images can be built from Maven projects (via Jib) similarly to existing builders (Docker, Bazel, Pack, Ko, etc.).

Changes:

  • Introduces a Maven/Jib builder and wires it into the image build selection flow.
  • Extends config to allow sources[].maven.run options.
  • Adds a Maven “helloworld” sample under e2e assets and a new example manifest for local Maven builds.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/e2e/assets/simple-app/helloworld/src/main/java/example/HelloWorld.java Adds a minimal Java entrypoint for the Maven/Jib sample app.
test/e2e/assets/simple-app/helloworld/pom.xml Adds a Maven project configured with the Jib Maven plugin.
pkg/kbld/image/git_test.go Adjusts env var and Close handling to satisfy errcheck expectations.
pkg/kbld/image/factory.go Wires the Maven/Jib builder into the image factory construction.
pkg/kbld/image/built.go Adds Maven/Jib as a build source option and routes builds through the new builder.
pkg/kbld/config/config.go Extends Source with a Maven field for Jib configuration.
pkg/kbld/config/config_jib.go Defines config structs for Jib run options.
pkg/kbld/builder/maven/jib.go Implements the Maven/Jib builder execution and Docker retagging.
pkg/kbld/builder/docker/docker.go Adds command logging for docker inspect.
hack/errcheck_excludes.txt Updates errcheck excludes for the logger writer type rename.
examples/simple-app-build-local-mvn/build.yml Adds a new example manifest for building a local Maven/Jib-backed image.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/simple-app-build-local-mvn/build.yml Outdated
Comment thread examples/simple-app-build-local-mvn/build.yml Outdated
Comment thread examples/simple-app-build-local-mvn/build.yml Outdated
Comment on lines +58 to +63
cmdArgs := []string{
"compile",
"jib:dockerBuild",
"-Dimage=" + targetImage,
"-Djib.allowInsecureRegistries=true",
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our downstream launch tool currently relies on this being enabled by default. We can look into making this configurable in a follow-up coordinated change.

Comment on lines +32 to +35
// Run executes the Maven Jib build.
func (b *Jib) Run(image, directory string,
opts config.SourceJibRunOpts) (ctlbdk.TmpRef, error) {
prefixedLogger := b.logger.NewPrefixedWriter(image + " | ")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This e2e test will require mvn available in the CI runner, I will need more information, we can skip this I believe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file that needs to be changed to install mvn is https://github.com/carvel-dev/kbld/blob/develop/hack/Dockerfile.dev. Give it a look and see if there is an easy way to add the Java and Maven environment.

@BulldromeQ BulldromeQ Jun 5, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Added default-jdk-headless and maven to hack/Dockerfile.dev. I also added a full E2E test suite in test/e2e/build_maven_jib_test.go and verified that Jib image building compiles and works successfully inside this environment. To completely resolve the race condition, I also updated the builder to build to a unique random temporary tag first before retagging.

@joaopapereira joaopapereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code as a whole looks good, but I would like to see some e2e tests. Take a look at https://github.com/carvel-dev/kbld/blob/develop/test/e2e/build_pack_test.go to make sure we have some assurance that this feature does not break in the future.

Made some form suggestions, mainly around imports and naming, with a NIT that I do not have a strong opinion about; I leave that to you.

My main concern is the fact that we build it and then ask the registry what the SHA is; this can cause race conditions or even malicious behavior.

Comment thread pkg/kbld/builder/maven/jib.go Outdated
Comment thread pkg/kbld/builder/maven/jib.go Outdated
Comment thread pkg/kbld/config/config_jib.go Outdated
Comment thread pkg/kbld/image/built.go Outdated
Comment thread pkg/kbld/image/built.go Outdated
Comment thread pkg/kbld/image/built.go Outdated
Comment thread pkg/kbld/image/factory.go Outdated
Comment thread pkg/kbld/image/factory.go Outdated
Comment thread pkg/kbld/builder/maven/jib.go
Comment thread pkg/kbld/builder/maven/jib.go Outdated
Comment on lines +78 to +84
if err := cmd.Run(); err != nil {
_, _ = prefixedLogger.Write([]byte(fmt.Sprintf(
"error: %s\n", err)))
return ctlbdk.TmpRef{}, err
}

inspectData, err := b.docker.Inspect(targetImage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat a race condition where if 2 builds are happening at the same time for the same image and no tags are provided, we do not know what image SHA we will get back. This might be a bit of a corner case, but I am not 100% sure I like this approach.
In other builders, we read the logs of the building tool and parse it. It may be more brittle if the verbiage changes between versions, but at least we know we tag the correct SHA.
Does maven output from jib provide the SHA in the logs?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The race only hits the latest fallback path — when a tag is set (our consumer always passes a unique one) the inspect can't collide. Ok to leave for now and revisit parsing the SHA from logs as a follow-up?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today, your consumer does, but if for some reason they stop doing it, we are relying on other people to keep consistency in our tools, which is concerning. In a world where we have multiple teams or eventually multiple agents doing work on a code base at any given time will only increase the possibility of this becoming an issue.
Another option we can use is the same technique we have for docker images building where we generate a temporary tag inside kbld code and then we use that tag, check https://github.com/carvel-dev/kbld/blob/develop/pkg/kbld/builder/docker/docker.go#L63, afterwards we also do the inspect and ensure that the image is tagged with the tag the user asks for.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where if 2 builds are happening at the same time for the same image and no tags are provided

Is this considered a poor build practice, or is this a common industry standard and we should handle that case? @joaopapereira

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an issue with the current design. We cannot predict what people will do with kbld, also this can also happen if someone is pushing the same tag to the repository.
What I want to make sure is that we cross our T's and dot our I's, the build already fail for a number of different reasons unrelated to kbld so we should make sure that kbld does behave well. Also this is not such a big change in the current code that we can do to ensure no randomess happens when building

@BulldromeQ BulldromeQ Jun 5, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and implemented the robust solution for this to completely eliminate any possible race condition: we now generate a unique, random temporary tag (via ctlb.TagBuilder{}) to run the maven build against, inspect that specific temporary tag, and then retag it to the desired user tag and stable/digest references.

@github-project-automation github-project-automation Bot moved this to In Progress in Carvel Jun 4, 2026
- Update copyright headers to 2026 in jib.go and config_jib.go
- Group imports (stdlib first) and use ctlbmvn alias for the maven
  builder package in jib.go, built.go, and factory.go
- Use value instead of pointer when resolving the image tag in jib.go
- Fix simple-app-build-local-mvn example: rename bazel-derived resource
  names/labels to mvn and drop the unsupported maven.run.name field

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@BulldromeQ

Copy link
Copy Markdown
Author

The code as a whole looks good, but I would like to see some e2e tests. Take a look at https://github.com/carvel-dev/kbld/blob/develop/test/e2e/build_pack_test.go to make sure we have some assurance that this feature does not break in the future.

Made some form suggestions, mainly around imports and naming, with a NIT that I do not have a strong opinion about; I leave that to you.

My main concern is the fact that we build it and then ask the registry what the SHA is; this can cause race conditions or even malicious behavior.

Thanks @joaopapereira , could you help me confirm that CI env have maven setup ahead so I could add some tests for these changes.

- Refactor Jib builder to build to a unique, random temporary tag first,
  then inspect and tag back to the target/stable tags, eliminating
  any potential tag/SHA race conditions with concurrent builds.
- Update hack/Dockerfile.dev to use default-jdk-headless to ensure
  reliable Java environment installation across different Debian versions.
- Document the optional tag property inside simple-app-build-local-mvn example.
- Add and integrate the new Maven Jib E2E test suite.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Wrap lines exceeding the 80-character boundary enforced by revive
  under the 'e2e' build tag config.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Comment thread pkg/kbld/builder/maven/jib.go Outdated
Comment thread pkg/kbld/builder/docker/docker.go Outdated
Comment thread pkg/kbld/image/git_test.go Outdated
Comment thread pkg/kbld/image/git_test.go Outdated
Comment thread pkg/kbld/image/built.go
Comment thread test/e2e/assets/maven-app/pom.xml
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@BulldromeQ

BulldromeQ commented Jun 8, 2026

Copy link
Copy Markdown
Author

@joaopapereira Update on the recent CI failures in the test-gh job (TestPackBuildAndPushSuccessful getting a 404 for jvmkill): I initially thought this was an external infrastructure flake, but it turns out it was indirectly caused by this PR!

By placing the pom.xml inside test/e2e/assets/simple-app/helloworld, the pack builder in the older E2E tests (which targets the parent simple-app dir) mistakenly detected the project as a Java application. This triggered the legacy Cloud Foundry OpenJDK Buildpack, which then failed because of its broken download link for jvmkill.

I've just pushed a commit that moves the Java app into its own dedicated directory at test/e2e/assets/maven-app. This cleanly separates the Go and Java assets and completely fixes the CI issue.

Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@joaopapereira

Copy link
Copy Markdown
Member

I was looking at cnb in docker hub and the latest sha is sha256:17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7 not sure if that will be enough but they did not update the image for 3 years. can you check with that image

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@BulldromeQ

Copy link
Copy Markdown
Author

@joaopapereira I've updated the pack builder image to the one you suggested (index.docker.io/cloudfoundry/cnb@sha256:17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7) in the e2e tests. Also, I've moved the java app into its own directory (test/e2e/assets/maven-app) so it won't conflict with the go app in simple-app. Let's see if the CI turns green now!

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Qi Hu <qi.hu@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@BulldromeQ

Copy link
Copy Markdown
Author

@joaopapereira The suggested builder image (17ea21162ba8c7717d3ead3ee3836a368aced7f02f2e59658e52029bd6d149e7) failed during detection with: ERROR: validating stack mixins: buildpack paketo-buildpacks/apache-tomcat@7.13.7 does not support stack io.buildpacks.stacks.bionic.

Because we've already fixed the root cause of the previous 404 error (by moving maven-app completely out of the simple-app folder so the older test no longer misidentifies it as a Java app), the original builder image (83270cf59e8944be0c544e45fd45a5a1f4526d7936d488d2de8937730341618d) should work perfectly again!

I've reverted the image SHA back to the original in the test. The CI should hopefully pass cleanly now.

@BulldromeQ BulldromeQ deployed to DockerHub E2E June 10, 2026 10:03 — with GitHub Actions Active

@joaopapereira joaopapereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joaopapereira

Copy link
Copy Markdown
Member

@BulldromeQ, thanks for the long feedback loop here. I am happy that we got to the current point.
We need to update https://github.com/carvel-dev/carvel/tree/develop/site/content/kbld/docs/develop to include the new configuration for Jib before we release a new kbld version. Can you please do that PR?

@joaopapereira joaopapereira merged commit ea02eee into carvel-dev:develop Jun 10, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Closed in Carvel Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

5 participants