Skip to content

Support for adding comments to generated build configuration #1490

Open
@breun

Description

@breun

I'm using MavenBuild.ConfigurationBuilder to generate some Maven plugin configuration in a project that builds on top of Spring Initializr, like this:

appMavenBuild.plugins().add("com.google.cloud.tools", "jib-maven-plugin") { pluginBuilder ->
    pluginBuilder.configuration { configurationBuilder ->
        configurationBuilder.add("container") { containerBuilder ->
            containerBuilder.add("jvmFlags") { jvmFlagsBuilder ->
                jvmFlagsBuilder
                    .add("jvmFlag", "-XX:InitialRAMPercentage=50")
                    .add("jvmFlag", "-XX:MaxRAMPercentage=50")
            }
        }
    }
}

This results in the following XML in pom.xml, as expected:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration>
    <container>
      <jvmFlags>
        <jvmFlag>-XX:InitialRAMPercentage=50</jvmFlag>
        <jvmFlag>-XX:MaxRAMPercentage=50</jvmFlag>
      </jvmFlags>
    </container>
  </configuration>
</plugin>

Now I'd like to add a comment to the generated jvmFlag entries, like this:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration>
    <container>
      <jvmFlags>
        <jvmFlag>-XX:InitialRAMPercentage=50</jvmFlag>
        <jvmFlag>-XX:MaxRAMPercentage=50</jvmFlag><!-- See https://example.com/some/url for heap memory sizing recommendations. -->
      </jvmFlags>
    </container>
  </configuration>
</plugin>

I believe the current MavenBuild.ConfigurationBuilder API doesn't provide a way to generate Maven configuration with comments, or am I missing something?

What are your thoughts about extending the API to allow adding comments? I can also see use cases for adding comments in other places in generated build configuration, so maybe it would be a good idea to add support for comments to all add(...) methods in classes in the io.spring.initializr.generator.buildsystem package?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions