Skip to content

'runOnlyOnce' coupled with Maven's --projects param makes plugin not run at all #387

@fmarot

Description

@fmarot

Describe the bug

In the case of a multi-module Maven project, when we use the 'runOnlyOnce=true' parameter coupled with 'injectAllReactorProjects=true', we expect the plugin to run once to calculate all git variables and we expect those variables to be available in children projects.

But this is not the case when we run Maven on a specific sub-project:
mvn install --projects mySubProject

neither when we use this command to resume from a specific sub-project:
mvn install -rf mySubProject

Steps to Reproduce

  • Here is the config in the parent pom:
			<plugin>
				<groupId>pl.project13.maven</groupId>
				<artifactId>git-commit-id-plugin</artifactId>
				<version>2.2.5</version>
				<executions>
					<execution>
						<id>get-the-git-infos</id>
						<goals>
							<goal>revision</goal>
						</goals>
						<phase>initialize</phase>
						<configuration>
							<generateGitPropertiesFile>false</generateGitPropertiesFile>
							<runOnlyOnce>true</runOnlyOnce>
							<injectAllReactorProjects>true</injectAllReactorProjects>
							<verbose>true</verbose>
							<skipPoms>false</skipPoms>
						</configuration>
					</execution>
				</executions>
			</plugin>

Expected behavior

mvn install --projects mySubProject

we expect to see the verbose logs of all the variables calculated.
But in fact we get this:

[INFO] --- git-commit-id-plugin:2.2.5:revision (get-the-git-infos) @ mySubProject ---
[INFO] runOnlyOnce is enabled and this project is not the top level project, skipping execution!

Additional context

version tested is the last released: 2.2.5

My analysis:

The code in GitCommitMojo looks like

if (runOnlyOnce) {
        if (!session.getExecutionRootDirectory().equals(session.getCurrentProject().getBasedir().getAbsolutePath())) {
          log.info("runOnlyOnce is enabled and this project is not the top level project, skipping execution!");
          return;
        }
      }

=> so the code expects to run at least once from Maven's ExecutionRootDirectory. But there it does not happen.

My suggestion is to set a variable (user variable ?) the first time the plugin is ran and when this variable is already set, we bypass the execution in case 'runOnlyOnce=true'
I will provide a Pull Request soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions