Skip to content
Closed
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ It's really simple to setup this plugin; below is a sample pom that you may base
-->
<skip>false</skip>

<!-- @since 2.1.12 -->
<!--
In a multi-module build, only run once. This probably won't "do the right thing" if your project has more than
one git repository. If you use this with the option 'generateGitPropertiesFile', it will only generate (or update)
the file in the directory where you started your build.

The git.* maven properties are available in all modules. Default value is 'false'.
-->
<runOnlyOnce>false</runOnlyOnce>

<!-- @since 2.1.9 -->
<!--
Can be used to exclude certain properties from being emited into the resulting file.
Expand Down Expand Up @@ -539,6 +549,7 @@ Optional parameters:
* **skipPoms** - `(default: true)` - Force the plugin to run even if you're inside of an pom packaged project.
* **failOnNoGitDirectory** - `(default: true)` *(available since v2.0.4)* - Specify whether the plugin should fail when a .git directory can not be found. When set to false and no .git directory is found the plugin will skip execution.
* **skip** - `(default: false)` *(available since v2.1.8)* - Skip the plugin execution completely.
* **runOnlyOnce** - `(default: false)` *(available since v2.1.12)* - In a multi-module build, only run once. This probably won't "do the right thing" if your project has more than one git repository. If you use this with the option 'generateGitPropertiesFile', it will only generate (or update) the file in the directory where you started your build. The git.* maven properties are available in all modules.
* **excludeProperties** - `(default: empty)` *(available since v2.1.9)* - Allows to filter out properties that you *don't* want to expose. This feature was implemented in response to [this issue](https://github.com/ktoso/maven-git-commit-id-plugin/issues/91), so if you're curious about the use-case, check that issue.
* **useNativeGit** - `(default: false)` *(available since v2.1.10)* - Uses the native `git` binary instead of the custom `jgit` implementation shipped with this plugin to obtain all information. Although this should usualy 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 option set to `false`) until you notice performance problems within your build (usualy when you have *hundreds* of maven modules).

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
<artifactId>maven-plugin-api</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.collect.Lists;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -256,6 +257,19 @@ public class GitCommitIdMojo extends AbstractMojo {
@SuppressWarnings("UnusedDeclaration")
private boolean skip = false;

/**
* In a multi-module build, only run once. This probably won't "do the right thing" if your project has more than
* one git repository. If you use this with the option 'generateGitPropertiesFile', it will only generate (or update)
* the file in the directory where you started your build.
*
* The git.* maven properties are available in all modules.
*
* @parameter default-value="false"
* @since 2.1.12
*/
@SuppressWarnings("UnusedDeclaration")
private boolean runOnlyOnce = false;

/**
* Can be used to exclude certain properties from being emited into the resulting file.
* May be useful when you want to hide {@code git.remote.origin.url} (maybe because it contains your repo password?),
Expand All @@ -272,6 +286,16 @@ public class GitCommitIdMojo extends AbstractMojo {
@SuppressWarnings("UnusedDeclaration")
private List<String> excludeProperties = Collections.emptyList();

/**
* The Maven Session Object
*
* @parameter expression="${session}"
* @required
* @readonly
*/
@SuppressWarnings("UnusedDeclaration")
protected MavenSession session;

/**
* The properties we store our data in and then expose them
*/
Expand All @@ -291,6 +315,13 @@ public void execute() throws MojoExecutionException {
return;
}

if (runOnlyOnce) {
if (!session.getExecutionRootDirectory().equals(session.getCurrentProject().getBasedir().getAbsolutePath())) {
log("already run once, return");
return;
}
}

if (isPomProject(project) && skipPoms) {
log("isPomProject is true and skipPoms is true, return");
return;
Expand Down