${project.artifactId} in parent pom.xml resolves odd

Viewed 11431

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>

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>

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?

3 Answers

Since Maven 3.6.1, inheritance can avoid appending any path to parent value by setting model attribute value to false for each url

src : maven-model-builder

You need to append following properties to SCM tag in your POM : <scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">...</scm>

It seems IntelliJ shows error, but at then end, it does the job perfect.

Adding to the already great background information given, in order to still deploy with a valid scm url, since Maven 3.5 you can correct the "module" name that gets appended per the project.directory property:

<properties>
    <project.directory>${project.artifactId}</project.directory>
</properties>

And then you just simplify your developerConnection to not include the artifactId anymore since it will be appended as the project.directory:

<scm>
    <developerConnection>scm:git:git@server:</developerConnection>
</scm>

Assuming this doesn't conflict with any other goals, that should allow a deploy goal to do its job with the correct git url for a non-multi-module Maven project where you've defined the scm.developerConnection in the parent pom.

When I run a deploy, I see maven doing a correct push like:

[INFO] Executing: /bin/sh -c cd /projectDir/proj && git push git@server:proj master:master
Related