sbt-version-policy icon indicating copy to clipboard operation
sbt-version-policy copied to clipboard

Only set mimaPreviousArtifacts when not set by other plugins

Open bjaglin opened this issue 2 years ago • 2 comments

Found via https://github.com/scalacenter/scalafix/issues/1673.

When mimaPreviousArtifacts is already set by another plugin that happens to run before SbtVersionPolicyPlugin, the value gets overriden (in the case of Scalafix, mimaPreviousArtifacts is set to compare module_2.13.$n against module_2.13.${n-1} through a local plugin for example).

Suggestion: when the value is already set (non-empty), do not provide a default.

bjaglin avatar Sep 21 '22 07:09 bjaglin

IIUC, the suggested fix is to rely on the fact that, by default, the MiMa plugin sets mimaPreviousArtifacts to an empty collection. So, if it is not empty, it means that someone set it and we don’t want to overwrite it. However, maybe in some cases, people do want sbt-version-policy to overwrite a value otherwise incorrectly set by another plugin. I wonder if the correct way to fix this issue is to change the order of application of the plugins (like you did)?

julienrf avatar Oct 18 '22 09:10 julienrf

I wonder if the correct way to fix this issue is to change the order of application of the plugins (like you did)?

It should be yes, unfortunately, I don't know a way in sbt to control the order of application of plugins you don't define yourself (I was lucky to be in control as it was an internal plugin that can be made aware of the presence of SbtVersionPolicyPlugin).

Suggestion: when the value is already set (non-empty), do not provide a default.

Now I realize this suggestion is not good, as it relies on the plugin application order (somewhat stable, but not deterministic/speced). SbtVersionPolicyPlugin might run first, and the value it sets may get overriden by another plugin, so it's a general problem.

bjaglin avatar Oct 18 '22 09:10 bjaglin