父pom.xml中的$ {project.artifactId}解析为奇数 [英] ${project.artifactId} in parent pom.xml resolves odd
问题描述
我有很多项目,它们的pom.xml中具有相同的URL:
I have a bulk full of projects which have the same URLs in their pom.xml:
<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>
因此,我认为将其放入父pom是一个好主意.xml .但是有效的pom会产生奇怪的$ {project.artifactId}:
So I thought it's a great idea to put that into a parent pom.xml. But the effective pom produces odd ${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>
您注意到,只有issueManagement.url可以正确解决.其他的完全是奇怪的,尤其是 $ {project.artifactId} .git -> localized.git/localized .我正在使用Maven 3.0.4.我在使用一些未定义的功能吗?是虫子吗?
You notice that only issueManagement.url was resolved correctly. The others are totally strange, especially ${project.artifactId}.git -> localized.git/localized. I'm using Maven 3.0.4. Am I using some undefined feature? Is it a bug?
推荐答案
是的,此行为令人困惑.
Yes, this behaviour is confusing.
也许最简单的理解方法是考虑Maven本身的构建方式.它在Subversion中,反应堆poms(带有<modules>
节的poms)也往往是模块本身的父poms.
Perhaps the easiest way to understand this is to consider how Maven itself is built. It's in Subversion, and the reactor poms (the poms with <modules>
sections) tend to also be the parent poms of the modules themselves.
project/pom.xml (artifactId: parent)
|-+ module1/pom.xml (artifactId: module1, inherits parent)
|-+ module2/pom.xml (artifactId: module2, inherits parent)
此处,父pom(project/pom.xml)包含一个<modules>
部分,并且也被module1和module2继承.
Here, the parent pom (project/pom.xml) contains a <modules>
section, and is also inherited by module1 and module2.
现在假设父级的SCM URL是svn://host/path/project/
:maven应该怎么做,这样就不必在两个模块中再次指定SCM URL?
Now suppose the SCM URL for parent is svn://host/path/project/
: what should maven do so that you don't have to specify the SCM URL again in the two modules?
好吧,module1的SCM URL是svn://host/path/project/module1
,Maven可以通过将artifactId添加到它从父pom继承的SCM URL中来进行计算.它只需要将artifactId附加到SCM URL.这就是它的作用.
Well, the SCM URL for module1 is svn://host/path/project/module1
, and Maven can compute that by adding the artifactId to the SCM URL it inherits from the parent pom. It simply needs to append the artifactId to the SCM URL. So that's exactly what it does.
这就是您所看到的行为:
So that's the behaviour you're seeing:
$ {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
您将在SCM URL和(我认为)project.url
和distributionMangement.site.url
中的URL中看到此行为.但是,Maven不假定issueManagement
URL结构遵循您的目录结构,这就是为什么您看到它正确继承的原因.
You will see this behaviour in the SCM URLs, and (I think) for project.url
and the URL in distributionMangement.site.url
. However, Maven doesn't assume that the issueManagement
URL structure follows your directory structure, which is why you see it inherited correctly.
这篇关于父pom.xml中的$ {project.artifactId}解析为奇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!