Maven 找不到 .git (dotGitDirectory)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31173467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven cannot find .git (dotGitDirectory)
提问by Vic K
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):
我有一个类似于这里提出的问题,但没有答案。在 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 is configured in parent-pom and nowhere else.
git-commit-id-plugin 在 parent-pom 中配置,没有其他地方。
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:
直到最近一切都很好:我能够使用 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
There is a .git folder under reactor module. As an experiment I removed it and get the same error for other modules.
在 reactor 模块下有一个 .git 文件夹。作为一个实验,我删除了它并在其他模块上得到相同的错误。
What could be a reason why one particular module cannot find .git folder during the build?
某个特定模块在构建过程中找不到 .git 文件夹的原因可能是什么?
Thanks.
谢谢。
回答by Samuel Kerrien
I bumped into this problem today and the solution is pretty clear looking at this well documented maven plugin:
我今天遇到了这个问题,通过查看这个有据可查的 maven 插件,解决方案非常清楚:
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):
在这里,您已在“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>
回答by Raja Anbazhagan
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.
由于 version2.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>
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.
该插件具有.git
在项目的当前目录和父目录中搜索存储库的内部逻辑。如果多模块项目位于同一个 git 存储库下,我不会太担心。
回答by charlb
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.
不是解决方案,但如果您想跳过父 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>
回答by Florian Lavorel
Updating maven to the latest version fixed the problem for me.
将 maven 更新到最新版本为我解决了这个问题。
回答by user1742058
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
我在干净的构建系统中遇到了类似的问题,这可能与他们不是“安装”的 git 用户有关。在我的本地,我看到
[info]git.build.user.name=myuser
[信息]git.build.user.name=myuser
etc, but nothing like that on the clean system.
等等,但在干净的系统上没有类似的东西。