Maven找不到.git(dotGitDirectory)

Vic*_*c K 5 git github maven

我有一个类似于此处提出的问题,但没有答案.在maven项目中有以下结构(标准):

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
Run Code Online (Sandbox Code Playgroud)

git-commit-id-plugin在parent-pom中配置,而在其他任何地方都没有.

直到最近一切都很好:我能够使用mvn clean install分别构建整个reactor项目和所有模块.然后我添加了一个新模块(比如说module_n1),我相信构建一直很好,直到大规模合并.现在我得到以下情况:reactor构建成功,每个模块分别从1到n构建成功.但是module_n1失败并出现以下错误:

 [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
Run Code Online (Sandbox Code Playgroud)

reactor模块下有一个.git文件夹.作为一项实验,我将其删除并为其他模块获得相同的错误.

在构建期间,一个特定模块无法找到.git文件夹的原因是什么?

谢谢.

Raj*_*gan 9

由于 version2.0.4标志failOnNoGitDirectorytrue默认的。将标志设置为false确保在.git目录不存在时跳过此目标。

<build>
    <plugins>
        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <configuration>
                <failOnNoGitDirectory>false</failOnNoGitDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

该插件具有.git在项目的当前目录和父目录中搜索存储库的内部逻辑。如果多模块项目位于同一个 git 存储库下,我不会太担心。


Sam*_*ien 8

我今天碰到了这个问题,解决方案非常清楚,看看这个记录良好的maven插件:

https://github.com/ktoso/maven-git-commit-id-plugin
Run Code Online (Sandbox Code Playgroud)

在这里你已经在'module_n1'中声明了插件,并且该文件夹中没有.git目录.如果.git目录位于父目录(例如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>
Run Code Online (Sandbox Code Playgroud)


cha*_*rlb 8

不是解决方案,但是如果您想在将项目添加到 git 之前跳过父 pom 中定义的 git-commit-id-plugin 执行,您可以覆盖 pom 中的执行。

        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
Run Code Online (Sandbox Code Playgroud)


Cha*_*awa -1

我在干净的构建系统中遇到了类似的情况,这可能与它们不是“安装”的 git 用户有关。在我本地,我看到

[信息]git.build.user.name=myuser

等等,但在干净的系统上没有这样的。