diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java index d23f22dbe2c..7f5a0d343e1 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java @@ -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; } diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java index cef61f90ef3..3b3367c23ff 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java @@ -3358,4 +3358,33 @@ void exclusionsAffectTransitiveDependencies() { ) ); } + + @Test + void systemPropertyTakesPrecedence() { + System.setProperty("hatversion", "2.3.0"); + rewriteRun( + pomXml( + """ + + com.mycompany.app + parent + 1.0-SNAPSHOT + pom + parent + http://www.example.com + + SYSTEM_PROPERTY_SHOULD_OVERRIDE_THIS + + + + org.springframework.hateoas + spring-hateoas + ${hatversion} + + + + """ + ) + ); + } }