Question

Can something in the parent pom take a value declared in the child pom?

Specifically I want to do something like this.

Parent:

<scm>
    <connection>scm:git:git@github.corp.com:team/${git.repo}.git</connection>
    <developerConnection>scm:git:git@github.corp.com:team/${git.repo}.git</developerConnection>
    <url>http://github.corp.com/team/${git.repo}</url>
</scm>

Child:

<properties>
    <git.repo>Foo</git.repo>
</properties>

Ideally the git.repo property is explicitly not set in the parent, such that the child must override either it, or override the scm section fully.

Was it helpful?

Solution 2

Can something in the parent pom take a value declared in the child pom?

Yes. In order to have a valid parent POM, however, I suggest providing a default/dummy value for ${git.repo} in the parent.

To deal with cases where a child POM does not override (i.e. redefine) ${git.repo} you could introduce a profile in the parent like so:

<profiles>
  <profile>
    <id>property-not-redefined</id>
    <activation>
      <activeByDefault>false</activeByDefault>
      <property>
        <name>git.repo</name>
        <value>your-default-value</value>
      </property>
    </activation>
    <build>
      <plugins>
        <!-- do something here -->
      </plugins>
    </build>
  </profile>
</profiles>

This profile becomes active when the git.repo property still has the default value.

OTHER TIPS

I'm adding this here since the general behavior is as explained in the Marcel answer, but particularly for the sample used with scm this might not work properly.

In maven 3.3.1 (and 3.3.3) doesn't work as expected.

Parent:

<properties>
    <git.project.name>uumds-commons</git.project.name>
    <git.scmUrl>https://github.com/raisercostin/${git.project.name}.git</git.scmUrl>
</properties>

<scm>
      <connection>scm:git:${git.scmUrl}</connection>
      <developerConnection>scm:git:${git.scmUrl}</developerConnection>
      <tag>HEAD</tag>
</scm>

Child:

<properties>
    <git.project.name>uumds-pdp</git.project.name>
</properties>

In effective pom (mvn help:effective-pom) in child becomes:

<properties>
  <git.project.name>uumds-pdp</git.project.name>
  <git.scmUrl>https://github.com/raisercostin/uumds-pdp.git</git.scmUrl>
</properties>

<scm>
  <connection>scm:git:https://github.com/raisercostin/uumds-pdp.git/uumds-pdp</connection>
  <developerConnection>scm:git:https://github.com/raisercostin/uumds-pdp.git/uumds-pdp</developerConnection>
  <tag>uumds-parent-0.9</tag>
</scm>

So it looks like if scm is not defined in child it automatically adds the project name to the connection.

Update: It seems that maven have some auto change url: ${project.artifactId} in parent pom.xml resolves odd and https://issues.apache.org/jira/browse/MNG-2290

The jira states

Maven has quite some elements where a URL or a path is modified automatically for child POMs (the ones I am currently aware of):

url
scm/connection
scm/developerConnection
scm/url
distributionManagement/site/url
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top