Skip to content

[MNG-7541] Native support for PowerShell to start Maven #8909

Open

Description

@jira-importer

Jurrian Fahner opened MNG-7541 and commented

Maven has two files in the bin dir:

command its use
mvn POSIX shell
mvn.cmd cmd.exe

On windows there are two ways to write scripts, by using cmd.exe or using powershell.

If you enter mvn in powershell it will look for mvn.ps1 on the PATH first. If it doesn't find anything it will execute mvn.cmd as fall-back.

When running maven for starting a server for development purposes and you do ctrl-c to exit the server it will ask the question: Terminate batch job (Y/N)?

As far as I know it is default behaviour of cmd.exe.

Well if I don't want to terminate, I wouldn't press ctrl-c. ;)

It is not the case (as far as I know that Microsoft is going to deprecate cmd.exe in favor of powershell: https://devblogs.microsoft.com/commandline/rumors-of-cmds-death-have-been-greatly-exaggerated/

Allthough I think it would be a good move for maven to have also a powershell script as well... It is possible to integrate elegant support for native help in powershell, get-help mvn.

But it also increases the maintenance effort as well. I don't know whether this cost outweigh the benefits, though...

By the way I would happy to contribute if it is appreciated.


Affects: 3.8.3

Issue Links:

  • MNG-7557 Rewrite Batch scripts (.cmd) in PowerShell (.ps1)
    ("is duplicated by")

  • MSHARED-1150 Support for PowerShell Maven executable

  • MWRAPPER-78 Rewrite mvnw.cmd in PowerShell (mvnw.ps1)

Remote Links:

Activity

  1. jira-importer commented on Sep 19, 2022

    @jira-importer
    Author

    Michael Osipov commented

    I have tought about this and the only benefit I see is that variables aren't automatically exported. What else?

  2. jira-importer commented on Sep 19, 2022

    @jira-importer
    Author

    Jurrian Fahner commented

    • The readability of the script can be improved because powershell is more feature rich.
    • It enables writing unit tests (this will improve readability and may also lower the barrier to entry): https://pester.dev/
    • Powershell is available since windows 7. Windows 10 and/or 11 are nowadays the base for many developer laptops/PCs.
    • We can get rid of cmd.exe script and replace it with powershell (which lowers maintainability effort), the mvn.cmd script will hold something like: 
      PowerShell.exe -command mvn.ps1

    It will likely not have a life altering impact probably... ;)

  3. jira-importer commented on Oct 4, 2022

    @jira-importer
    Author

    Michael Osipov commented

    I'd be in favor to review a PR. One issue is though that some of our components might explicitly call mvn.cmd.

  4. jira-importer commented on Oct 4, 2022

    @jira-importer
    Author

    Michael Osipov commented

    Those need to be reviewed:

    $ grep -r --include='*.java' \\.cmd .
    ./plugins/tools/scm/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java:                String winMvnPath = mvnPath + ".cmd";
    ./shared/invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java:            File executableFile = new File( baseDirectory, executable + ".cmd" );
    

    I can take cake of Maven SCM, sjaranowski, do you want to address Invoker?

  5. jira-importer commented on Oct 7, 2022

    @jira-importer
    Author

    Jurrian Fahner commented

    Michael Osipov Shall I create a PR based on the implementation for mvn.ps1?

    We also need to take care of the mvnw.cmd. Do we want to have it in one PR or can we implement the functionality in several PRs?

  6. jira-importer commented on Oct 7, 2022

    @jira-importer
    Author

    Michael Osipov commented

    Core and Wrapper are two projects. So separate PRs. Willing to review mvn.ps1.

  7. jira-importer commented on Oct 8, 2022

    @jira-importer
    Author

    Michael Osipov commented

    Jurrian Fahner, please note that in Maven 4 the start scripts have been broken up into single components. This is what you have to provide also. The scripts have been simplified in Maven 4 and aren't compatible with Maven 3.

  8. jira-importer commented on Feb 7, 2023

    @jira-importer
    Author

    Guillaume Nodet commented

    I wonder if it would make sense to remove the .cmd script instead of keeping both .ps1 and .cmd scripts.

  9. jira-importer commented on Feb 7, 2023

    @jira-importer
    Author

    Michael Osipov commented

    This needs to be fully tested at least with all of our components and properly announced. Not trivial.

  10. jira-importer commented on Mar 26, 2025

    @jira-importer
    Author

    Guillaume Nodet commented

    Is this an effort we want to pursue ?
    Do we need both scripts or should we get rid of the cmd script and use that one ?

  11. added
    enhancement
    priority:trivial
    on Jul 7, 2025
  12. modified the milestones: , 4.x on Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:trivial

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions