Intellij 无法使用 $revision 解析 pom.xml。Maven 工作

nep*_*tom 4 intellij-idea pom.xml maven parent-pom

${revision}标签可以在 pom.xml 中使用,如下所述

\n\n

具有这样的目录结构:

\n\n
fix\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pom.xml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 parent\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pom.xml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 example\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pom.xml\n
Run Code Online (Sandbox Code Playgroud)\n\n

pom.xml有:

\n\n
<project>\n    <groupId>intellij</groupId>\n    <artifactId>fix</artifactId>\n    <version>${revision}</version>\n\n    <properties>\n        <project.parent.basedir>parent</project.parent.basedir>\n    </properties>\n\n    <packaging>pom</packaging>\n    <modules>\n        <module>parent</module>\n        <module>example</module>\n    </modules>\n    <modelVersion>4.0.0</modelVersion>\n</project>\n
Run Code Online (Sandbox Code Playgroud)\n\n

父/pom.xml有:

\n\n
<project>\n    <groupId>intellij</groupId>\n    <artifactId>parent</artifactId>\n\n    <properties>\n        <revision>1.0.0</revision>\n    </properties>\n\n    <parent>\n        <groupId>intellij</groupId>\n        <artifactId>fix</artifactId>\n        <version>${revision}</version>\n    </parent>\n\n    <packaging>pom</packaging>\n    <modelVersion>4.0.0</modelVersion>\n</project>\n
Run Code Online (Sandbox Code Playgroud)\n\n

example/pom.xml

\n\n
<project>\n    <groupId>example</groupId>\n    <artifactId>example</artifactId>\n\n    <parent>\n        <groupId>intellij</groupId>\n        <artifactId>parent</artifactId>\n        <version>${revision}</version>\n        <relativePath>../parent/pom.xml</relativePath>\n    </parent>\n    <modelVersion>4.0.0</modelVersion>\n</project>\n
Run Code Online (Sandbox Code Playgroud)\n\n

IntelliJ 报告:

\n\n

在此输入图像描述

\n\n

mvn在终端上解析它很好并且有效。

\n\n

这破坏了 IntelliJ 中的很多东西。
\n我用 IntelliJ 2019.2 尝试过这个

\n

khm*_*ise 5

只是一个提示。如果您mvn clean对结构执行简单的 on 命令,您将看到以下内容:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] parent 1.0.0 ....................................... SUCCESS [  0.146 s]
[INFO] example 1.0.0 ...................................... SUCCESS [  0.003 s]
[INFO] fix ${revision} .................................... SUCCESS [  0.002 s]
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

这表明这里有问题...因为版本属性无法在根 pom 中解析...这就是 IDEA IntelliJ 告诉您有问题的原因...正如您所看到的最后一行中的根项目表明存在问题。

如果您将修订属性正确移动到根项目(修复)中,您将看到以下内容:

[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ example ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for fix 1.0.0:
[INFO] 
[INFO] fix ................................................ SUCCESS [  0.106 s]
[INFO] parent ............................................. SUCCESS [  0.003 s]
[INFO] example ............................................ SUCCESS [  0.002 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.255 s
[INFO] Finished at: 2020-01-28T20:56:22+01:00
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

在此输出中,您会看到fix第一行是正确的。

我强烈建议正确更改您的结构,并且不要<relativePath>../parent/pom.xml</relativePath>在您的example项目中使用,这表明您的目录结构并不代表您在 pom 文件中创建的真实结构。

这应该会产生我创建的 github 示例项目中给出的结构:

https://github.com/khmarbaise/so-question-1

除此之外,请将flatten-maven-plugin文档中描述的添加到您的项目中,否则如果您使用mvn clean installmvn clean deploy