Skip to content
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

Don't ask for version number when removing snapshot from version. #709

Closed
garretwilson opened this issue Sep 18, 2022 · 4 comments · Fixed by #712
Closed

Don't ask for version number when removing snapshot from version. #709

garretwilson opened this issue Sep 18, 2022 · 4 comments · Fixed by #712
Labels
Milestone

Comments

@garretwilson
Copy link

If I have a project using a *-SNAPSHOT version, the Versions Maven Plugin set goal has a removeSnapshot option that removes the -SNAPSHOT suffix (for when if I'm ready to release the final version, for example). I can call it from the command line like this, and it works pretty well. (See also https://stackoverflow.com/a/46036141.)

mvn versions:set -DremoveSnapshot -DgenerateBackupPoms=false

I want set removeSnapshot to be idempotent. In other words, just like I can call set foo=bar again and again in some example database or key-value store, I expect to call set removeSnapshot again and again with no change in behavior.

Unfortunately once I call mvn versions:set -DremoveSnapshot -DgenerateBackupPoms=false the second time (i.e. if the -SNAPSHOT suffix has already been removed, it asks for a version number!

Enter the new version to set 1.2.3: :

This behavior breaks batch/script files that do pre-release activities if they are run again (after realizing that a dependency needs to be updated, or whatever). Moreover the behavior doesn't even make sense: if I ask the plugin to remove the -SNAPSHOT suffix, why perform extra actions if the -SNAPSHOT suffix is missing? Rather the plugin should be performing fewer operations if the -SNAPSHOT suffix is missing; it should simply do nothing at all.

(Without looking at the code, it's easy to suppose that the removeSnapshot functionality might have been added after the main version:set functionality was written, and inadvertently the developer let the logic fall back to the default versions:set logic if in reality there is nothing at all that needs done.)

Please remove the user interaction for removeSnapshot when the -SNAPSHOT suffix is not present, or at least provide an option to make this functionality idempotent (although I can't imagine of any use cases where someone would want to be asked for the version—if they wanted to be asked, they would have left off the removeSnapshot parameter altogether).

Based on the totality of circumstances, it would seem this behavior is a bug.

@jarmoniuk
Copy link
Contributor

Makes sense, but I wonder: if somebody depended on the current behaviour, this requested change would break it for them. Perhaps a kind of a "force" switch (although this leads to creating more and more switches)?

I'm inclined to simply going with the suggested change and waiting till someone shouts.

Opinions?

jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Sep 19, 2022
@jarmoniuk
Copy link
Contributor

@garretwilson just FYI, you can disable the prompter by using -DinteractiveMode=false in your invocation

@garretwilson
Copy link
Author

garretwilson commented Sep 19, 2022

just FYI, you can disable the prompter by using -DinteractiveMode=false in your invocation

I was really happy to read that there was a workaround. I got suspicious when it wasn't mentioned in the documentation. And then I actually tried it:

mvn versions:set -DremoveSnapshot -DgenerateBackupPoms=false -DinteractiveMode=false

Did you actually try it? 😁

To reiterate the gist of this ticket: -DremoveSnapshot isn't something that is supposed to be interactive in the first place, and it's likely inadvertent coding that prompts for a new version when -SNAPSHOT is not present.

In any case, -DinteractiveMode=false doesn't seem to do anything.

@jarmoniuk
Copy link
Contributor

Gotcha. My test actually relies on it, but I did not set it via command line.

--batch-mode or -B is the right switch. It's not a plugin option, it's a maven option.

But what it does is - it disables the prompt and the maven target fails with an error message. So it will still break your jobs, but it won't hang them.

If I had to use the current version, I'd probably use something to run versions:set conditionally, e.g. a test on the pom.xml if it matches a regex pattern.

In any case, the PR is there waiting to be reviewed and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants