Skip to content

Commit

Permalink
When resolving maven pom properties give system properties precedence.
Browse files Browse the repository at this point in the history
This matches Maven's own behavior.
  • Loading branch information
sambsnyd committed Jan 16, 2025
1 parent c80874b commit 2586748
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public String getPackaging() {
if (property == null) {
return null;
}
String propVal = properties.get(property);
// Maven allows system properties to override project properties
// This facilitates the usage of "-D" arguments on the command line to customize builds
String propVal = System.getProperty(property, properties.get(property));
if (propVal != null) {
return propVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3358,4 +3358,33 @@ void exclusionsAffectTransitiveDependencies() {
)
);
}

@Test
void systemPropertyTakesPrecedence() {
System.setProperty("hatversion", "2.3.0");
rewriteRun(
pomXml(
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<url>http://www.example.com</url>
<properties>
<hatversion>SYSTEM_PROPERTY_SHOULD_OVERRIDE_THIS</hatversion>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>${hatversion}</version>
</dependency>
</dependencies>
</project>
"""
)
);
}
}

0 comments on commit 2586748

Please sign in to comment.