父pom.xml中的$ {project.artifactId}解析为奇数

Mar*_*sch 7 maven

我有大量的项目,在他们的pom.xml中有相同的URL:

<url>https://github.com/malkusch/${project.artifactId}</url>

<scm>
    <connection>scm:git:git://github.com/malkusch/${project.artifactId}.git</connection>
    <developerConnection>scm:git:git@github.com:malkusch/${project.artifactId}.git</developerConnection>
    <url>https://github.com/malkusch/${project.artifactId}</url>
</scm>

<issueManagement>
    <system>github</system>
    <url>https://github.com/malkusch/${project.artifactId}/issues</url>
</issueManagement>
Run Code Online (Sandbox Code Playgroud)

所以我认为把它放到父pom.xml中是一个好主意.但有效的pom会产生奇怪的$ {project.artifactId}:

<parent>
  <groupId>de.malkusch.parent</groupId>
  <artifactId>oss-parent</artifactId>
  <version>1.1-SNAPSHOT</version>
</parent>
<groupId>de.malkusch.localized</groupId>
<artifactId>localized</artifactId>
<url>https://github.com/malkusch/localized/localized</url>
<scm>
  <connection>scm:git:git://github.com/malkusch/localized.git/localized</connection>
  <developerConnection>scm:git:git@github.com:malkusch/localized.git/localized</developerConnection>
  <url>https://github.com/malkusch/localized/localized</url>
</scm>
<issueManagement>
  <system>github</system>
  <url>https://github.com/malkusch/localized/issues</url>
</issueManagement>
Run Code Online (Sandbox Code Playgroud)

您注意到只有issueManagement.url已正确解析.其他的都很奇怪,特别是$ {project.artifactId} .git - > localized.git/localized.我正在使用Maven 3.0.4.我使用了一些未定义的功能吗?这是一个错误吗?

Mar*_*lis 9

是的,这种行为令人困惑.

也许最简单的理解方法是考虑如何构建Maven本身.它在Subversion中,反应堆poms(带有<modules>部分的poms )往往也是模块本身的父poms.

project/pom.xml (artifactId: parent)
|-+ module1/pom.xml (artifactId: module1, inherits parent)
|-+ module2/pom.xml (artifactId: module2, inherits parent)
Run Code Online (Sandbox Code Playgroud)

这里,父pom(project/pom.xml)包含一个<modules>节,并且还由module1和module2继承.

现在假设父级的SCM URL是svn://host/path/project/:maven应该做什么,这样您就不必在两个模块中再次指定SCM URL?

那么,module1的SCM URL是svn://host/path/project/module1,并且Maven可以通过将artifactId添加到它从父pom继承的SCM URL来计算.它只需要将artifactId附加到SCM URL.所以这正是它的作用.

这就是你所看到的行为:

$ {project.artifactId} .git变为localized.git/localized如下:

localized  -> from ${project.artifactId} in the inherited SCM URL
.git       -> from the the inherited SCM URL
/localized -> from adding the artifactId to the inherited SCM URL
Run Code Online (Sandbox Code Playgroud)

您将在SCM URL中看到此行为,并且(我认为)project.url和URL中的URL distributionMangement.site.url.但是,Maven并不认为issueManagementURL结构遵循您的目录结构,这就是您看到它正确继承的原因.

  • 哇!这种行为是否有记录?我对$ {project.artifactId}的上下文敏感性印象深刻. (2认同)