Plugin compatibility tester is re-adding test-scoped dependencies rather than merely updating them #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Running PCT on
pipeline-utility-steps
with an updatedworkflow-step-api
, I was getting the following error:… followed by a series of test failures because
workflow-step-api
was missing when running the tests.Evaluation
The pom for
pipeline-utility-steps
looks like this:So PCT was trying to update this dependency from 2.19 to 2.21. Unfortunately, here's the edit PCT came up with:
Unfortunately, this edit is just plain wrong. It edited the first two dependencies correctly, but it also inserted a new test-scoped dependency at the end, which was missing the classifier that the original (and still present!) test-scoped dependency had. The result is a malformed POM that can't build.
Solution
Fix the bug. Test-scoped dependencies should be edited in place rather than added at the end as synthetic dependencies.
Implementation
Looking at the code, I saw it was maintaining a
toReplaceTestUsed
map to determine what was replaced and what needs to be added as "synthetic". But the only time a test-scoped dependency was placed into that map was if that test-scope dependency wasn't already present as a non-test-scoped dependency. This isn't true in the case ofpipeline-utility-steps
and we cannot assume it is true in the general case. The solution is simple: after doing the replacement, check if the thing we replaced was test-scoped or not. If it was test-scoped, update thetoReplaceTestUsed
map so that the dependency isn't re-added as "synthetic" later on in the code.Testing Done
Confirmed that the problematic duplicate dependency was inserted into the POM before this change and was not inserted into the POM after this change, and that the "Some problems were encountered while building the effective model" Maven error was no longer present.