If I have a private registry and I want to publish the generated docker image I need to provide username, password, and url in the maven pom.xml.

...
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
    </image>
    <docker>
      <publishRegistry>
        <username>USERNAME</username>
        <password>PASSWORD</password>
        <url>URL</url>
      </publishRegistry>
    </docker>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>build-image</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I would like to be able to send this variables over the command line as follows:

mvn spring-boot:build-image \
-DskipTests \
-Dspring-boot.build-image.imageName=nexus:8870/rcl/op-risk-ui:test \
-Dspring-boot.build-image.publishRegistry.username=<USERNAME> \
-Dspring-boot.build-image.publishRegistry.password=<PASSWORD>
-Dspring-boot.build-image.publishRegistry.url=<URL>

Currently the following variables doesnt exist for the command line:

  • -Dspring-boot.build-image.publishRegistry.username
  • -Dspring-boot.build-image.publishRegistry.password
  • Dspring-boot.build-image.publishRegistry.url

I believe they should be created here: https://github.com/spring-projects/spring-boot/blob/82b90d57496ba85be316b9eb88a36d81f2cc9baa/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java

Comment From: philwebb

I'm not sure how easy this will be to fix. I suspect that we can't just add a property attribute to the docker @Parameter because it's a complex type. We'll need to dig into the internals of Maven.

In the meantime, you can probably do something like this:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
    </image>
    <docker>
      <publishRegistry>
        <username>${spring-boot.build-image.publishRegistry.username}</username>
        <password>${spring-boot.build-image.publishRegistry.password}</password>
        <url>${spring-boot.build-image.publishRegistry.url}</url>
      </publishRegistry>
    </docker>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>build-image</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Comment From: snicoll

It's indeed not possible to map a nested parameter unless we create a parameter for the sole purpose to be mapped. This is one of the downsides of using such structure with Maven plugins. I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

Comment From: scottfrederick

I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

I agree with @snicoll, as Maven makes it simple enough to create your own properties and use them in the plugin configuration.

Comment From: wilkinsona

I too agree with @snicoll. We've already seen some examples of users defining their own properties such as this from

29756:

<configuration>
    <image>
        <name>${docker.image-name}</name>
    </image>
    <docker>
        <publishRegistry>
            <username>${docker.credentials.username}</username>
            <password>${docker.credentials.password}</password>
        </publishRegistry>
    </docker>
</configuration>

This feels like the right way to go to me.

Comment From: philwebb

Thanks everyone. I'm going to repurpose this one as documentation issue.

Comment From: ffroliva

I think, then, that this scenario should be added to the documentation since I understand this is quite a common use case. The example where you add this variable directly in the pom.xml doesn't really represent the best practice and will almost always be avoided, therefor showing one approach to go would be important for the whole community.

Em seg., 16 de mai. de 2022 às 13:14, Stéphane Nicoll ***@***.*** escreveu:

It's indeed not possible to map a nested parameter unless we create a parameter for the sole purpose to be mapped. This is one of the downsides of using such structure with Maven plugins. I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/31024#issuecomment-1127595644, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF67VG6ZVFAVWVZRBAUECF3VKI3YTANCNFSM5V2ZOBYA . You are receiving this because you authored the thread.Message ID: @.***>

Comment From: snicoll

@ffroliva please consult the history of the issue before commenting. That's exactly what this issue is about.

Comment From: scottfrederick

Closing in favor of #34517