diff --git a/README.md b/README.md index 9be303d..e54c343 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,21 @@ set -e On `pre-commit` git phase, the hook triggers the `git-code-format:on-pre-commit` which formats the code of the modified java files using `google-java-format`. +### Configuring Maven Executable Path +By default, the plugin will generate the following maven path + +```shell +"${env.M2_HOME}/bin/mvn" +``` + +If you want to use the global `mvn` variable, you can configure it using the `useGlobalMavenExecutable` property. + +```xml + + true + +``` + ### Advanced pre-commit pipeline hook If you wish to modify the output of the pre-commit hook, you can set the `preCommitHookPipeline` configuration. diff --git a/src/main/java/com/cosium/code/format/InstallHooksMojo.java b/src/main/java/com/cosium/code/format/InstallHooksMojo.java index 7cd5be1..a5dada6 100644 --- a/src/main/java/com/cosium/code/format/InstallHooksMojo.java +++ b/src/main/java/com/cosium/code/format/InstallHooksMojo.java @@ -74,6 +74,13 @@ public class InstallHooksMojo extends AbstractMavenGitCodeFormatMojo { @Parameter(property = "gcf.preCommitHookPipeline", defaultValue = "") private String preCommitHookPipeline; + /** + * Set to `true` to use the global `mvn` executable in the hooks script otherwise will default to + * the complete path for `mvn` found via `maven.home` variable + */ + @Parameter(property = "gcf.useGlobalMavenExecutable", defaultValue = "false") + private boolean useGlobalMavenExecutable; + public void execute() throws MojoExecutionException { if (!isExecutionRoot()) { getLog().debug("Not in execution root. Do not execute."); @@ -107,7 +114,7 @@ private void doExecute() throws IOException { private void writePluginHooks(Path hooksDirectory) throws IOException { getLog().debug("Removing legacy pre commit hook file"); Files.deleteIfExists(hooksDirectory.resolve(legacyPluginPreCommitHookFileName())); - getLog().debug("Rmeoved legacy pre commit hook file"); + getLog().debug("Removed legacy pre commit hook file"); getLog().debug("Writing plugin pre commit hook file"); executableManager @@ -115,7 +122,7 @@ private void writePluginHooks(Path hooksDirectory) throws IOException { .truncateWithTemplate( () -> getClass().getResourceAsStream(BASE_PLUGIN_PRE_COMMIT_HOOK), StandardCharsets.UTF_8.toString(), - mavenEnvironment.getMavenExecutable(debug).toAbsolutePath(), + useGlobalMavenExecutable ? "mvn" : mavenEnvironment.getMavenExecutable(debug).toAbsolutePath(), pomFile().toAbsolutePath(), mavenCliArguments()); getLog().debug("Written plugin pre commit hook file");