aleksandr-m / gitflow-maven-plugin

The Git-Flow Maven Plugin supports various Git workflows, including GitFlow and GitHub Flow. This plugin runs Git and Maven commands from the command line.
https://aleksandr-m.github.io/gitflow-maven-plugin/
Apache License 2.0
493 stars 181 forks source link

Maven Wrapper mvnw and mvnw.cmd built-in support #246

Closed nhojpatrick closed 2 years ago

nhojpatrick commented 4 years ago

If mvnExecutable is blank, then automatically use mvnw or mvnw.cmd depending upon OS, if avaliable.

Tested on Mac, that if mvnw is present then the current working directory will be used instead of just mvn.

aleksandr-m commented 4 years ago

@nhojpatrick Have you tested this on Windows? I remember that there were some problems executing mvn.cmd instead of mvn on Windows.

nhojpatrick commented 4 years ago

@aleksandr-m tested on a windows 10 vm that didn't have mvn installed/setup, using Command Prompt

C:\john\aleksandr-m_gitflow-maven-plugin>mvnw com.amashchenko.maven.plugin:gitflow-maven-plugin:1.14.1-SNAPSHOT:release -DpostReleaseGoals=deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.amashchenko.maven.plugin:gitflow-maven-plugin >----------
[INFO] Building gitflow-maven-plugin 1.14.1
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- gitflow-maven-plugin:1.14.1-SNAPSHOT:release (default-cli) @ gitflow-maven-plugin ---
[INFO] Checking for uncommitted changes.
[INFO] Fetching remote branch 'origin develop'.
[WARNING] There were some problems fetching remote branch 'origin develop'. You can turn off remote branch fetching by setting the 'fetchRemote' parameter to false.
[INFO] Fetching remote branch 'origin master'.
[INFO] Comparing local branch 'master' with remote 'origin/master'.
[INFO] Checking out 'develop' branch.
[INFO] Checking for SNAPSHOT versions in dependencies.
[INFO] Cleaning and testing the project.
What is release version? [1.14.1]:
[INFO] Version is blank. Using default version.
[INFO] Checking out 'master' branch.
[INFO] Merging (--no-ff) 'develop' branch.
[INFO] Creating '1.14.1' tag.
[INFO] Running Maven goals: deploy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  47.233 s
[INFO] Finished at: 2020-09-05T22:27:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.amashchenko.maven.plugin:gitflow-maven-plugin:1.14.1-SNAPSHOT:release (default-cli) on project gitflow-maven-plugin: release: [INFO] Scanning for projects...
[ERROR] [INFO]
[ERROR] [INFO] ---------< com.amashchenko.maven.plugin:gitflow-maven-plugin >----------
[ERROR] [INFO] Building gitflow-maven-plugin 1.14.1
[ERROR] [INFO] ----------------------------[ maven-plugin ]----------------------------
...
...
...
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [INFO] BUILD FAILURE
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [INFO] Total time:  12.125 s
[ERROR] [INFO] Finished at: 2020-09-05T22:27:01+01:00
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project gitflow-maven-plugin: Failed to deploy artifacts: Could not transfer artifact com.amashchenko.maven.plugin:gitflow-maven-plugin:jar:1.14.1 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Transfer failed for https://oss.sonatype.org/service/local/staging/deploy/maven2/com/amashchenko/maven/plugin/gitflow-maven-plugin/1.14.1/gitflow-maven-plugin-1.14.1.jar 401 Unauthorized -> [Help 1]
[ERROR] [ERROR]
[ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] [ERROR]
[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Which errors because deploy doesn't have a valid username and password to actually upload as part of the deploy phase. So it must have found mvnw.cmd.

aleksandr-m commented 3 years ago

@nhojpatrick Can it be done in that way to use the same maven which user currently uses to run this plugin? Something like if mvnExecutable is blank then see which maven had started plugin if wrapper then use it, if not then use the default.

nhojpatrick commented 3 years ago

@nhojpatrick Can it be done in that way to use the same maven which user currently uses to run this plugin? Something like if mvnExecutable is blank then see which maven had started plugin if wrapper then use it, if not then use the default.

Using mavenSession.getSystemProperties() you can use;

So @aleksandr-m any preference in a pattern match for env key env.JAVA_MAIN_CLASS_* with value org.apache.maven.wrapper.MavenWrapperMain, or key maven.home with value pattern .*/wrapper/dists/.*?

Working on testing both but it looks like both approaches can be used on a mac using maven 3.6.3.

nhojpatrick commented 3 years ago

@aleksandr-m decided to use both main class check and maven home check to determine if triggered by mvnw.

I think this is now ready to be merged.

Also noticed extra config for maven-compiler-plugin, so use my goto global properties defaults for any maven project.

nhojpatrick commented 3 years ago

@aleksandr-m have done some more testing and believe it works on both linux and windows, as well for builds within openshift and other cicd tools that default to mvnw if it's present.

nhojpatrick commented 3 years ago

@aleksandr-m want to add you as a reviewer and request a review but don't have permissions to do that.

nhojpatrick commented 3 years ago

@aleksandr-m Could this be reviewed and hopefully merged please.

aleksandr-m commented 3 years ago

@nhojpatrick Can you revert changes to properties. I'm more comfortable with them as they are now. I'll try to find time to review this in a few days.

aleksandr-m commented 2 years ago

@nhojpatrick I had more time to test this feature, and seems using sun.java.command property works fine, at least in oracle/openjdk. See 72da5071405e18d8f969f94d2bc291ef2aeded0f. Thanks for the idea and initial code.