Skip to content

Conversation

sdeleuze
Copy link
Contributor

Reading Gradle documentation and seeing other similar code samples, I don't think the environment.get() part is needed, and it looks not idiomatic.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 20, 2024
@@ -7,7 +7,7 @@ plugins {

// tag::env[]
tasks.named<BootBuildImage>("bootBuildImage") {
environment.set(environment.get() + mapOf("BP_JVM_VERSION" to "17"))
environment.set(mapOf("BP_JVM_VERSION" to "17"))
Copy link
Member

Choose a reason for hiding this comment

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

The intent is to add a BP_JVM_VERSION to any existing entries. Won't this replace any existing entries in the environment map such that it now only contains BP_JVM_VERSION -> 17?

Copy link
Member

Choose a reason for hiding this comment

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

environment is a MapProperty and it has a put(String, String) method. I think that's what we should call. I'm not sure if there's some Kotlin DSL support for it, or if it should just be environment.put("BP_JVM_VERSION", "17").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good point, I think I was confused by the fact the other samples in this page are also using environment.set(mapOf("key" to "value")). I guess we should fix those as well.

I think environment.put("BP_JVM_VERSION", "17") is indeed what should be used. I have tested it successfully here. I don't think there is a better DSL than that.

Let me try to update other code samples accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

@sdeleuze sdeleuze force-pushed the boot-build-image-env-gradle branch from 1b43b3b to a7829e3 Compare June 20, 2024 08:53
@wilkinsona wilkinsona changed the title Refine code sample in boot-build-image-env.gradle.kts Update Kotlin DSL examples that configure the environment of bootBuildImage to be additive Jun 20, 2024
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 20, 2024
@wilkinsona wilkinsona added this to the 3.2.x milestone Jun 20, 2024
@mhalbritter mhalbritter self-assigned this Jun 28, 2024
@mhalbritter
Copy link
Contributor

Thanks Sébastien!

@mhalbritter mhalbritter modified the milestones: 3.2.x, 3.2.8 Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants