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).
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
.
Parent:
<project>
<artifactId>parent-pom</artifactId>
<properties>
<scmurl>www.mysite.com</scmurl>
</properties>
<scm>
<connection>${scmurl}/${artifactId}</connection>
</scm>
</project>
Child:
<project>
<parent>
<artifactId>parent-pom</artifactId>
</parent>
<artifactId>child-pom</artifactId>
</project>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With