【问题标题】:Maven cannot find .git (dotGitDirectory)Maven 找不到 .git (dotGitDirectory)
【发布时间】:2015-09-19 07:51:30
【问题描述】:

我有一个类似于here 的问题,但没有答案。 在 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

git-commit-id-plugin 是在 parent-pom 中配置的,其他地方没有。

直到最近一切都很好:我能够使用 mvn clean install 分别构建整个反应器项目和所有模块。 然后我添加了一个新模块(比如说module_n1),我相信构建一直很好,直到大规模合并。 现在我得到了以下情况:反应堆构建成功,每个模块从 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

reactor 模块下有一个 .git 文件夹。作为一个实验,我删除了它并在其他模块上得到了同样的错误。

在构建过程中某个特定模块找不到 .git 文件夹的原因可能是什么?

谢谢。

【问题讨论】:

  • 您可以将以下内容添加到您的 maven 命令 -Dmaven.gitcommitid.skip=true

标签: git maven github


【解决方案1】:

自版本2.0.4 起,标志failOnNoGitDirectory 默认为true。将标志设置为false 以确保在.git 目录不存在时跳过此目标。

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

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

【讨论】:

    【解决方案2】:

    我今天遇到了这个问题,看看这个有据可查的 maven 插件,解决方案很清楚:

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

    在这里,您已在“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>
    

    【讨论】:

    • 请问,您是否将应用程序部署到 heroku 平台?我有同样的问题,但不确定“dotGitDirectory”是否应该设置为。
    • 嗨@emeraldjava,我相信这个问题与部署平台无关。它与 Maven 不知道在哪里可以找到它试图收集 SCM 信息的 .git 存储库有关。就我而言,我有一个多模块项目,因此 .git 位于父目录中,因此我不得不告诉插件。我希望这会有所帮助;)
    【解决方案3】:

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

            <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    

    【讨论】:

      【解决方案4】:

      将 maven 更新到最新版本为我解决了这个问题。

      【讨论】:

        【解决方案5】:

        如果插件来自父 POM,您可以通过此属性在子 POM 中跳过它

        <properties>
            <maven.gitcommitid.skip>true</maven.gitcommitid.skip>
        </properties>
        

        【讨论】:

          【解决方案6】:

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

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

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

          【讨论】:

          • 没有安装 git 用户之类的东西,这里插件想要找到一个 .git 目录来运行它的查询,因为配置插件的项目没有,但我假设父目录之一,插件抱怨...
          猜你喜欢
          • 1970-01-01
          • 2012-01-07
          • 2019-04-20
          • 2021-02-14
          • 2019-05-27
          • 2020-12-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多