Skip to content

Allow to override useNativeGit from command line #433

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

Merged
merged 2 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/using-the-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ It's really simple to setup this plugin; below is a sample pom that you may base

Although this should usually give your build some performance boost, it may randomly break if you upgrade your git version and it decides to print information in a different format suddenly.
As rule of thumb, keep using the default `jgit` implementation (keep this `false`) until you notice performance problems within your build (usually when you have *hundreds* of maven modules).

With version *3.0.2* you can also control it using the commandline option `-Dmaven.gitcommitid.nativegit=true`
-->
<useNativeGit>false</useNativeGit>

Expand Down
24 changes: 23 additions & 1 deletion src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,26 @@ public class GitCommitIdMojo extends AbstractMojo {
* Set this to {@code 'true'} to use native Git executable to fetch information about the repository.
* It is in most cases faster but requires a git executable to be installed in system.
* By default the plugin will use jGit implementation as a source of information about the repository.
*
* @since 2.1.9
*/
@Parameter(defaultValue = "false")
boolean useNativeGit;

/**
* Option to be used in command-line to override the value of {@code 'useNativeGit'} specified in
* the pom.xml, or its default value if it's not set explicitly.
*
* NOTE / WARNING:
* Do *NOT* set this property inside the configuration of your plugin.
* Please read https://github.com/git-commit-id/maven-git-commit-id-plugin/issues/315
* to find out why.
*
* @since 3.0.2
*/
@Parameter(property = "maven.gitcommitid.nativegit", defaultValue = "false")
boolean useNativeGitViaCommandLine;

/**
* Set this to {@code 'true'} to skip plugin execution.
* @since 2.1.8
Expand Down Expand Up @@ -557,8 +572,15 @@ private void logProperties() {
}
}

private boolean isUseNativeGit() {
if (System.getProperty("maven.gitcommitid.nativegit") != null) {
return useNativeGitViaCommandLine;
}
return useNativeGit;
}

private void loadGitData(@Nonnull Properties properties) throws GitCommitIdExecutionException {
if (useNativeGit) {
if (isUseNativeGit()) {
loadGitDataWithNativeGit(properties);
} else {
loadGitDataWithJGit(properties);
Expand Down