且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-08-21 19:09:52

是的,此行为令人困惑.

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.urldistributionMangement.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.