Issue
I'm having an issue where maven is not properly substituting properties into my repository URLs if and only if there is a parent pom defined. This is particularly a problem because the parent pom is IN the remote repository, so I need to have the parent pom defined.
minimum reproducible example:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.group</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0</version>
<relativePath/>
</parent>
<groupId>com.group</groupId>
<artifactId>project-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>project</name>
<description>test project</description>
<properties>
<nexus.url>https://nexus.myorganization.net</nexus.url>
</properties>
<repositories>
<repository>
<id>nexus-server</id>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
</repositories>
</project>
Using this pom, I get the error message Cannot access ${nexus.url}/repository/maven-snapshots/...
so clearly it is not replacing the property with the actual value.
If I remove the <parent>
section of the POM, then suddenly property substitution begins working just fine:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.group</groupId>
<artifactId>project-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>project</name>
<description>test project</description>
<properties>
<nexus.url>https://nexus.myorganization.net</nexus.url>
</properties>
<repositories>
<repository>
<id>nexus-server</id>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
</repositories>
<!-- adding this dependency so that Maven is forced to download from the repository -->
<dependencies>
<!-- some dependency here -->
</dependencies>
</project>
I know its working properly because I can see in maven's output the line Downloading from nexus-server: https://nexus.myorganization.net/repository/maven-releases/...
Any ideas?
Solution
Thanks to the commenters, the reason is because the property resolution does not occur until after the parent pom has been resolved, so that there are no property conflicts between current pom and parent pom.
More details provided at tickets MNG-2569 and MNG-624 (source).
Answered By - Alex A