Duplicate artifactId in child pom

荒凉一梦 提交于 2019-12-01 05:59:29

edwardmlyte,

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

Fundamental Problem

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

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.

Your 2 options are:

Redundant but Simple

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

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

It's annoying but relatively straightforward.

Efficient but Dodgy

Have parent-pom contain the following:

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

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

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

Hope that helps.

My answer is not all that dissimilar to @333kenshin and was in fact derived from it, but I think that it results in a slightly terser paste.

In my parent pom I have added the following to <properties>

<git.account>xenworks</git.account>
<git.base>bitbucket.org/${git.account}/${project.artifactId}</git.base>
<git.conn>scm:git:https://${git.base}.git</git.conn>
<git.devConn>scm:git:ssh://git@${git.base}.git</git.devConn>
<git.url>https://${git.base}</git.url>

Now in the children and parent I can define scm as follows.

<scm>
  <connection>${git.conn}</connection>
  <developerConnection>${git.devConn}</developerConnection>
  <url>${git.url}</url>
  <tag>HEAD</tag>
</scm>

the final contribution I'd like to make is there is an open bug on this in the Maven Jira

Gerold Broser

Where does ${scmurl} come from? The property is called url.

If one adapts parent-pom accordingly:

 <scmurl>www.mysite.com</scmurl>

... the behavior is as described in the OQ:

/parent-pom$ mvn help:effective-pom
  ...
  <scm>
    <connection>www.mysite.com/parent-pom</connection>
  </scm>
  ...


<relativePath>../parent-pom</relativePath> (assuming they are siblings in the file system) has to be added to child-pom if parent-pom has not been installed into the local Maven repo (yet). Otherwise the following will fail:

/child-pom$ mvn help:effective-pom
  ...
  <scm>
    <connection>www.mysite.com/child-pom/child-pom</connection>
  </scm>
  ...

This looks strange to me at first sight, too. I'm still scouring the docs to find a (logical) explanation for this.

Replacing ${artifactId} with ${project.artifactId} – as suggested in the comments – does not help.

Repeating <scm><connection>${scmurl}/${artifactId}</connection></scm> in child-pom helps:

/child-pom$ mvn help:effective-pom
  ...
  <scm>
    <connection>www.mysite.com/child-pom</connection>
  </scm>
  ...

However, I'd consider khmarbaise's comments to the question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!