Maven cannot find .git (dotGitDirectory)
Asked Answered
C

7

21

I have an issue similar to what has been asked here, but there is no answer. Have following structure in maven project (which is standard):

parent-pom - which is a parent for all others
    |_reactor - which is a concrete project, parent-pom is a parent
        |_module_1 - reactor is a parent
        |_module_2
        ...
        |_module_n

git-commit-id-plugin is configured in parent-pom and nowhere else.

Until recently everything was fine: I was able to build both the whole reactor project and all modules separately with mvn clean install. Then I added a new module (let's say module_n1), I believe the build had been going fine until massive merge. Now I got following situation: reactor build is successful, each module separately from 1 to n builds successfully as well. But module_n1 fails with following error:

 [ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.1.7:revision (default) on project module_n1: .git directory could not be found! Please specify a valid [dotGitDirectory] in your pom.xml

There is a .git folder under reactor module. As an experiment I removed it and get the same error for other modules.

What could be a reason why one particular module cannot find .git folder during the build?

Thanks.

Christianism answered 1/7, 2015 at 23:47 Comment(2)
You can add the following to your maven command -Dmaven.gitcommitid.skip=trueWong
Only "-Dmaven.gitcommitid.skip=true" worked for me. "<failOnNoGitDirectory>false</failOnNoGitDirectory>" did not.Bever
P
26

Since version 2.0.4 The flag failOnNoGitDirectory is true by default. Set the flag to false to make sure this goal is skipped when .git directory doesn't exist.

<build>
    <plugins>
        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <configuration>
                <failOnNoGitDirectory>false</failOnNoGitDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

The plugin has an internal logic of searching for .git repositories in the current and parent directories of the project. I wouldn't worry much if the multi-module project sits under the same git repository.

Phenica answered 11/6, 2018 at 9:33 Comment(0)
G
12

I bumped into this problem today and the solution is pretty clear looking at this well documented maven plugin:

https://github.com/ktoso/maven-git-commit-id-plugin

Here you have declared the plugin in 'module_n1' and there is no .git directory in that folder. The solution would be to configure the plugin as follow if the .git directory is in the parent directory (eg. reactor):

        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <version>2.1.15</version>
            <executions>
                <execution>
                    <goals>
                        <goal>revision</goal>
                     </goals>
                </execution>
            </executions>
            <configuration>
                <dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
                <!-- more config here as you see fit -->
            </configuration>
        </plugin>
Goldeneye answered 9/9, 2015 at 6:14 Comment(2)
Can i ask, were you deploying an app to the heroku platform? I've the same issue but am unsure that the 'dotGitDirectory' should be set to.Indoor
Hi @emeraldjava, I believe this issue is independent of the deployment platform. It is rather related to maven no knowing where to find the .git repo where it is trying to collect SCM infos. In my case I had a multi-module project so the .git was in the parent directory, thus I had to tell the plugin so. I hope that helps ;)Goldeneye
R
10

Not a solution, but if you want to skip git-commit-id-plugin execution defined in a parent pom until project is added to git, you can override execution in your pom.

        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
Rocky answered 1/3, 2017 at 14:54 Comment(0)
P
1

If the plugin is coming from a parent POM you can skip it in the child by this property

<properties>
    <maven.gitcommitid.skip>true</maven.gitcommitid.skip>
</properties>
Progressive answered 29/6, 2021 at 14:49 Comment(0)
D
0

Updating maven to the latest version fixed the problem for me.

Diacritic answered 28/11, 2016 at 14:22 Comment(0)
B
0

I make fixes by change to correct JDK I was using runtime jdk 8 and compile time jdk 17 we need to fix both side same

Biotite answered 6/8 at 15:21 Comment(0)
E
-1

I ran into something similar in a clean build system and it may be related to their not being a git user "installed". On my local, I see

[info]git.build.user.name=myuser

etc, but nothing like that on the clean system.

Electrochemistry answered 24/7, 2015 at 18:47 Comment(1)
No such thing as installing a git user, here the plugin wants to find a .git directory to run its queries against, because the project in which the plugin is configured doesn't have one but I assume one of the parent directory, the plugin complains ...Goldeneye

© 2022 - 2024 — McMap. All rights reserved.