Skip to content

Support configuring bootBuildImage's environment through the command line#48792

Closed
HuitaePark wants to merge 1 commit intospring-projects:mainfrom
HuitaePark:support-cli-option
Closed

Support configuring bootBuildImage's environment through the command line#48792
HuitaePark wants to merge 1 commit intospring-projects:mainfrom
HuitaePark:support-cli-option

Conversation

@HuitaePark
Copy link
Contributor

This PR is intentionally opened as a draft to gather feedback on the overall approach.

Related Issue

Closes #45306

Goal

Add support for passing Buildpacks environment variables to the bootBuildImage task via CLI options.

This is particularly useful for CI pipelines and automated local workflows (e.g., Kubernetes, Skaffold, or Tilt), where modifying build.gradle or pom.xml to set dynamic values is often undesirable.

Background

In BootBuildImage, the environment configuration is currently defined as a MapProperty<String, String>:

@Input
public abstract MapProperty<String, String> getEnvironment();

However, Gradle’s "Option" annotation does not support Map types, making it impossible to directly expose this property as a CLI option.

As discussed in #45306, this PR explores an alternative approach where CLI-provided values are collected separately as a list and then mapped into the existing environment property.

Approach

  1. Introduce a CLI-only input:
    Use an "Internal" ListProperty to capture the raw options provided by the user.

  2. Validation & Parsing:
    The input strings are parsed into key-value pairs at execution time.

  • Strictly enforces the KEY=VALUE format.

  • If the format is invalid (e.g., missing the = separator), the task fails immediately with a GradleException to provide clear feedback to the user.

  • Example error: "Invalid value for option '--environment'. Expected 'NAME=VALUE' but got '...'."

  1. Merge:
    The parsed values are merged into the existing environment (MapProperty), allowing CLI options to complement or override build script configurations.

CLI Usage

./gradlew bootBuildImage \
  --environment BP_LIVE_RELOAD_ENABLED=true \
  --environment BPL_JAVA_NMT_ENABLED=false
  • The --environment option is repeatable
  • Each entry must be provided in KEY=VALUE format

Accumulate command line --environment values in a ListProperty and merge them with the
configured environment when building the effective environment map. Add a test that
verifies multiple entries are accepted and propagated.

Closes spring-projectsGH-45306

Signed-off-by: HuitaePark <[email protected]>
@wilkinsona wilkinsona changed the title Make bootBuildImage --environment option repeatable Support configuring bootBuildImage's environment through the command line Jan 12, 2026
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 12, 2026
@wilkinsona wilkinsona modified the milestones: 4.1.x, 4.1.0-M1 Jan 12, 2026
wilkinsona pushed a commit that referenced this pull request Jan 12, 2026
Accumulate command line --environment values in a ListProperty and
merge them with the configured environment when building the
effective environment map. Add a test that verifies multiple entries
are accepted and propagated.

See gh-48792

Signed-off-by: HuitaePark <[email protected]>
@wilkinsona
Copy link
Member

Thanks very much, @HuitaePark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configuring bootBuildImage's environment through the command line

3 participants