子pom中重复的artifactId [英] Duplicate artifactId in child pom

查看:544
本文介绍了子pom中重复的artifactId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望父pom定义一些要继承的子pom的某些属性.但是,当我尝试在父pom的这些属性之一中使用artifactId时,它会在孩子的有效pom中重复.下面是非常基本的示例.假设我拥有pom所需的所有有效字段(groupId,版本,包装等).

I want a parent pom to define some properties for numerous child poms to inherit. However when I try and use the artifactId within one of these properties in the parent pom, it duplicates in the child's effective pom. Very basic example below. Assume I have all the valid fields needed for poms (groupId, version, packaging etc).

父pom的有效pom的scm连接值为www.mysite.com/parent-pom.但是孩子的有效pom的scm连接值为www.mysite.com/child-pom/child-pom.如何获得连接网址的属性和一般结构的这种继承,而没有重复的artifactId.我希望子pom具有www.mysite.com/child-pom的scm连接.

The parent pom's effective pom has a scm connection value of www.mysite.com/parent-pom. But the child's effective pom has a scm connection value of www.mysite.com/child-pom/child-pom. How do I gain this inheritance of the property and general structure of the connection url, without the duplicate artifactId. I want the child pom to have a scm connection of www.mysite.com/child-pom.

父母:

<project>
  <artifactId>parent-pom</artifactId>
  <properties>
    <scmurl>www.mysite.com</scmurl>
  </properties>
  <scm>
    <connection>${scmurl}/${artifactId}</connection>
  </scm>
</project>

孩子:

<project>
  <parent>
    <artifactId>parent-pom</artifactId>
  </parent>
  <artifactId>child-pom</artifactId>
</project>

推荐答案

edwardmlyte

edwardmlyte,

针对您要执行的操作,有两种解决方案,但都不是最佳选择.

There are 2 solutions to what you're trying to do, but neither of them are optimal.

基本问题

如果Maven SCM插件检测到在您的父母中定义了<scm>块,但在您的孩子中定义了 NOT ,那么这将导致您孩子的SCM路径只是父母的子目录.在您的情况下,您的父母的URL本身包含${project.artifactId}会产生额外的折痕,该褶皱会在子​​级别上被插值,然后再再次添加artifactId.

If Maven SCM plugin detects that <scm> block has been defined in your parent but NOT in your child, then it will reason that your child's SCM path is simply the subdir of the parent. In your case there's an additional wrinkle that your parent's url itself contains ${project.artifactId} which gets interpolated at the child level prior to tacking on the artifactId again.

基本上,它正在执行以下操作:

Basically, it's doing the following:

project.scm.connection=${parent.scm.connection}/${project.artifactId}
project.scm.connection=${scmurl}/${project.artifactId}/${project.artifactId}
project.scm.connection=www.mysite.com/child-pom/child-pom

您父母的URL包含${artifactId}的事实加剧了混淆,但是即使将URL硬编码为www.mysite.com/parent-pom/,您也无法避免SCM插件认为child-pom是以下内容的子目录的事实父母的网址,因此只需将其添加到路径的末尾即可.

The fact that your parent's url contains ${artifactId} compounds the confusion, but even if you hardcode the url to www.mysite.com/parent-pom/ you won't be able to get around the fact that SCM plugin thinks child-pom is a subdir of the parent's url and so will simply tack it onto the end of the path.

您的2个选项是:

冗余但简单

将以下内容放入每个孩子的pom.xml文件中:

Put the following into every child's pom.xml file:

<scm>
    <connection>${scmurl}/${artifactId}</connection>
</scm>

这很烦人,但相对简单.

It's annoying but relatively straightforward.

高效但狡猾

父pom包含以下内容:

Have parent-pom contain the following:

<scm>
    <connection>${scmurl}/</connection>
</scm>

这将导致每个孩子都有正确的url,但是父母本身会被弄乱.

That will result in each child will have correct url, but the parent itself will be messed up.

您可以通过将父母的正确网址放入个人资料中来解决该问题:

You can get around that problem by putting the parent's correct url into a profile:

<profile>
    <id>parent-profile</id>
    <scm>
        <connection>${scmurl}/parent-pom</connection>
    </scm>
</profile>


$ mvn -Pparent-profile ...

这种情况不太明显,更容易出现人为错误,但可以避免编辑每个孩子的pom文件的需要.

It's less obvious and prone to manual error, but it'll avoid the need to edit each child's pom file.

希望有帮助.

这篇关于子pom中重复的artifactId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆