-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inherit image configuration from the parent pom #360
Comments
you should be able to do this by specifying see here: https://maven.apache.org/pom.html under the |
@jgangemi, right, thanks! However maven is not really predictable in this case so just for the record
|
heh - that's not us, that's maven. i think you can add |
I completely agree that Maven leaves something to be desired in this area. However, what is the plugin's behavior if two image blocks with the name are found? Does it merge these or are they treated separately? -- looking at the code I it looks like they are treated separately. The ability to append to or override an image configuration (e.g. just its run/env block) would be useful and allow you to work around Maven's all or nothing inheritance. For example: parent: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PORT>80</PORT>
<USER>root</USER>
<PASSWORD>secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> child: <configuration>
<images combine.children="append">
<image>
<name>foo</name>
<run>
<env>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> The effective child pom would look like this: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PORT>80</PORT>
<USER>root</USER>
<PASSWORD>secret</PASSWORD>
</env>
</run>
</image>
<image>
<name>foo</name>
<run>
<env>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> So what would be needed is a way to merge the configurations of image configurations with the same name. For external configuration the plugin already supports resolving configuration from other sources: Something similar could be used to match images with the same name and merge the configurations. The precedence would be defined by the order of the images in the list by default or by a new attribute. In our use case the parent pom contains the default image configuration and child poms need to be able to customize (add/override) some attributes as well as add new images. The latter works great with Maven's append instruction, but the former poses a bit of a problem. What are your thoughts about adding support for merging image configurations with the same name? |
@vjkoskela it is up to maven and configuration you set for nodes, |
Thanks @osigida I will take a look again. However, the configuration is stored in a list and Maven merges based on the element name. As a result, the Fabric8 plugin uses <images>
<image>
<name>imageNameA</name>
...
</image>
<image>
<name>imageNameB</name>
...
</image>
</images> Therefore Maven cannot understand if two image blocks are logically related (based on the nested name attribute). From the link you posted:
In order to merge elements which represent the same image it should not be a list but a map where the "key" is the name of the image. Maven supports maps as documented below and then I believe we could rely on Maven's merge/override/append semantics to manipulate the xml as desired: https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Mapping_Maps For example: <images>
<imageNameA>
...
</imageNameA>
<imageNameB>
...
</imageNameB>
</images> But this is a major backwards incompatible change to the plugin hence my proposal to perform the merge in the plugin. The example above I posted how Maven would treat multiple = Override = parent: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PORT>80</PORT>
<USER>root</USER>
<PASSWORD>secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> child: <configuration>
<images combine.children="override">
<image>
<name>foo</name>
<run>
<env>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> The effective child pom would look like this: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> = Merge = parent: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PORT>80</PORT>
<USER>root</USER>
<PASSWORD>secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> child: <configuration>
<images> <!-- Merge is the default -->
<image>
<name>foo</name>
<run>
<env>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> The effective child pom would look like this: <configuration>
<images>
<image>
<name>foo</name>
<run>
<env>
<PORT>80</PORT>
<USER>root</USER>
<PASSWORD>top-secret</PASSWORD>
</env>
</run>
</image>
</images>
</configuration> This works great for a single image, and even multiple images -- however, it assumes that the images are in the same order and ALL images from the parent are declared in the child. Partial image declarations (e.g. override only a subset) or other changes to image declaration order will wreak havoc on the effective configuration. You can blame Maven for this, but in my opinion if the images were modeled as a map keyed by the image name instead of a list then Maven could merge the correct image configuration together with its existing functionality. Let me know if I've missed something here. |
if you have multiple configuration blocks and they share the same image name and you aren't using any of the for example, i have the following profiles which are activated using a
|
This allows merging of configuration using the normal Maven behavior. Signed-off-by: Wolfgang Kritzinger <wkritzinger@atlassian.com>
This allows merging of configuration using the normal Maven behavior. Signed-off-by: Wolfgang Kritzinger <wkritzinger@atlassian.com>
Signed-off-by: Wolfgang Kritzinger <wkritzinger@atlassian.com>
Hi All,
I have a parent pom where a general image configuration is defined in pluginManagement section (all child projects build this image, with very few changes, like java start class)
Sometimes I'd like to build extra image together with one defined in the parent pom.
Is there a way to handle it via configuration inheritance?
Have tried few things but didn't succeeded, only one image defined in child pom was built.
The text was updated successfully, but these errors were encountered: