Skip to content

Commit 88deffe

Browse files
authored
Merge pull request #443 from TheSnoozer/feature-387
#387: make runOnlyOnce run on the first project (and make it work when maven's --projects param are specified)
2 parents 98d1e2d + 963a0ad commit 88deffe

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

maven/docs/using-the-plugin.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,23 @@ It's really simple to setup this plugin; below is a sample pom that you may base
254254
Explanation:
255255
Use with caution!
256256
257-
In a multi-module build, only run once. This means that the plugins effects will only execute once, for the parent project.
257+
In a multi-module build, only run once. This means that the plugins effects will only execute
258+
once for the first project in the execution graph. If `skipPoms` is set to true (default)
259+
the plugin will run for the first non pom project in the execution graph (as listed in the reactor build order).
258260
This probably won't "do the right thing" if your project has more than one git repository.
259261
260262
Important: If you're using `generateGitPropertiesFile`, setting `runOnlyOnce` will make the plugin
261-
only generate the file in the directory where you started your build (!).
263+
only generate the file in the project build directory which is the first one based on the execution graph (!).
262264
263265
Important: Please note that the git-commit-id-plugin also has an option to skip pom project (`<packaging>pom</packaging>`).
264266
If you plan to use the `runOnlyOnce` option alongside with an aggregator pom you may want to set `<skipPoms>false</skipPoms>`.
265267
266-
The `git.*` maven properties are available in all modules.
268+
For multi-module build you might also want to set `injectAllReactorProjects` to make
269+
the `git.*` maven properties available in all modules.
270+
271+
Note:
272+
prior to version 4.0.0 the plugin was simply using the execute once applied for the parent project
273+
(which might have skipped execution if the parent project was a pom project).
267274
-->
268275
<runOnlyOnce>false</runOnlyOnce>
269276

maven/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,24 @@ public void execute() throws MojoExecutionException {
419419
}
420420

421421
if (runOnlyOnce) {
422-
if (!session.getExecutionRootDirectory().equals(session.getCurrentProject().getBasedir().getAbsolutePath())) {
423-
log.info("runOnlyOnce is enabled and this project is not the top level project, skipping execution!");
422+
List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects();
423+
MavenProject firstProject = sortedProjects.stream()
424+
// skipPoms == true => find first project that is not pom project
425+
.filter(p -> {
426+
if (skipPoms) {
427+
return !isPomProject(p);
428+
} else {
429+
return true;
430+
}
431+
})
432+
.findFirst()
433+
.orElse(session.getCurrentProject());
434+
435+
log.info("Current project: '" + session.getCurrentProject().getName() +
436+
"', first project to execute based on dependency graph: '" + firstProject.getName() + "'");
437+
438+
if (!session.getCurrentProject().equals(firstProject)) {
439+
log.info("runOnlyOnce is enabled and this project is not the first project (perhaps skipPoms is configured?), skipping execution!");
424440
return;
425441
}
426442
}

0 commit comments

Comments
 (0)