Skip to content

Add preliminary Maven goals to invoke from the pre-commit script#361

Open
duke1995 wants to merge 1 commit into
Cosium:masterfrom
duke1995:feature/add-preliminary-maven-goals-to-pre-commit-script
Open

Add preliminary Maven goals to invoke from the pre-commit script#361
duke1995 wants to merge 1 commit into
Cosium:masterfrom
duke1995:feature/add-preliminary-maven-goals-to-pre-commit-script

Conversation

@duke1995

Copy link
Copy Markdown
Contributor

Make it possible to configure preliminary Maven goals that should be invoked before invoking the main git-code-format:on-pre-commit goal from the pre-commit script.

See also: Cannot use multiple sourceDirectories · Issue #52 · Cosium/git-code-format-maven-plugin

Make it possible to configure preliminary Maven goals that should be
invoked before invoking the main git-code-format:on-pre-commit goal
from the pre-commit script.

See also: [Cannot use multiple sourceDirectories · Issue Cosium#52 · Cosium/git-code-format-maven-plugin](Cosium#52 (comment))
@duke1995 duke1995 closed this Jun 29, 2026
@duke1995 duke1995 deleted the feature/add-preliminary-maven-goals-to-pre-commit-script branch June 29, 2026 09:04
@duke1995 duke1995 restored the feature/add-preliminary-maven-goals-to-pre-commit-script branch June 29, 2026 09:05
@duke1995 duke1995 reopened this Jun 29, 2026
@reda-alaoui

Copy link
Copy Markdown
Member

Please add an automated test

@duke1995

duke1995 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Hello @reda-alaoui

I have no experience writing a Maven plugin, and therefore no experience writing a proper test for it either.

For the PoC, I based my changes on the code that already exists in the project right now, in particular on the code for the propertiesToAdd config property. However, I don't find a specific test for the propertiesToAdd config property (or one of the other config properties) which I could use as a starting point for a test for the new config property (but maybe I overlooked it).

I only did a manual test by doing a mvn clean install of my feature branch and using that new SNAPSHOT version of the plugin on a test project to verify the generated pre-commit script.

  <properties>
    <git-code-format-maven-plugin.version>6.1-SNAPSHOT</git-code-format-maven-plugin.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>com.cosium.code</groupId>
        <artifactId>git-code-format-maven-plugin</artifactId>
        <version>${git-code-format-maven-plugin.version}</version>
        <dependencies>
          <!-- Enable https://github.com/google/google-java-format -->
          <dependency>
            <groupId>com.cosium.code</groupId>
            <artifactId>google-java-format</artifactId>
            <version>${git-code-format-maven-plugin.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <preliminaryGoals>
            <preliminaryGoal>build-helper:add-test-source@add-integration-test-source</preliminaryGoal>
            <preliminaryGoal>build-helper:add-test-source@add-acceptance-test-source</preliminaryGoal>
          </preliminaryGoals>
          <!-- enable hook execution verbose mode -->
          <!-- <propertiesToAdd>
          <prop>-X</prop>
        </propertiesToAdd> -->
        </configuration>
      </plugin>
    </plugins>
  </build>

With the above config, the contents of the generated pre-commit script is as follows:

#!/bin/bash
set -e
"C:/dev/java/maven/default/bin/mvn.cmd" -f "C:/dev/prj/my-group/my-project/pom.xml" build-helper:add-test-source@add-integration-test-source build-helper:add-test-source@add-acceptance-test-source com.cosium.code:git-code-format-maven-plugin:on-pre-commit 

Kind regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants