Skip to content

[MNG-6983] Plugin key can get out of sync with artifactId and groupId#372

Closed
PPazderski wants to merge 1 commit intoapache:masterfrom
PPazderski:MNG-6983
Closed

[MNG-6983] Plugin key can get out of sync with artifactId and groupId#372
PPazderski wants to merge 1 commit intoapache:masterfrom
PPazderski:MNG-6983

Conversation

@PPazderski
Copy link
Copy Markdown

I came here because of a project where some maven plugins are not executed without any warning or error. Debugging the issue brought me to the implementation of the key field in Plugin.java. It constructs the key once on first use from the plugins groupId and artifactId. The key is not updated when either of this values changes.

It is not easy for me to say where exactly this construct start to fail, but take a look on the following screenshot. At one point ManagementModelMerger.mergePluginContainerPlugins tries to enhance the child pom plugin instance with the version information from the parents pluginManagement. But it fails to match both plugin instances. Both plugins have the same (interpolated) groupId and artifactId but different keys. Obviously for one instance getKey() was called before the groupId was interpolated but not for the other, resulting in different keys for the same plugin.

mvn-debug

My suggested fix is to basically follow the TODO comment found on key. Reset the key if groupId or artifactId changes. Since the key calculation is so simple I actually see no reason to cache it at all.
Furthermore, while writing this description, I noticed that the implementation of ReportPlugin is very similar (looks like it was copy&pasted at one point) and it already does what I propose for this pull request.

PS: an additional note and warning if you want to debug the current code. All debuggers I know tend to call the toString method when inspecting object instances. In case of Plugin this also triggers the one time calculation of key. I.e. inspecting the Plugin object in debugger can change the instance state and as result the issue does not appear anymore or at a different place as without debugging.

The plugin key is build as combination of artifactId and groupId but not
updated if either of these two ids change.
This can be a problem if artifactId or groupId is a variable. The calculated
key will likely contain the unresolved property and is not updated once the
variable is interpolated.
@asfgit asfgit closed this in 39641ac Oct 3, 2020
asfgit pushed a commit that referenced this pull request Jun 26, 2021
The plugin key is build as combination of artifactId and groupId but not
updated if either of these two ids change.
This can be a problem if artifactId or groupId is a variable. The calculated
key will likely contain the unresolved property and is not updated once the
variable is interpolated.

This closes #372
@jira-importer
Copy link
Copy Markdown

Resolve #8395

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants