diff --git a/src/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java b/src/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java index 3443fd622c..5b257e34a7 100644 --- a/src/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java +++ b/src/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; @Value @@ -88,10 +89,7 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { Xml.Document d = super.visitDocument(document, ctx); // Return early if the parent appears to be within the current repository, as properties defined there will be updated - if (d.getRoot().getChild("parent") - .flatMap(parent -> parent.getChild("relativePath")) - .flatMap(Xml.Tag::getValue) - .isPresent()) { + if (getResolutionResult().parentPomIsProjectPom()) { return d; } diff --git a/src/test/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersionTest.java b/src/test/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersionTest.java index 9262e9e05a..5a85e2b782 100644 --- a/src/test/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersionTest.java +++ b/src/test/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersionTest.java @@ -20,7 +20,6 @@ import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import org.openrewrite.test.SourceSpec; import static org.openrewrite.java.Assertions.mavenProject; import static org.openrewrite.maven.Assertions.pomXml; @@ -123,74 +122,64 @@ void basicWithVariables() { } @Test - void overrideRemoteParent() { + void updateLocalParent() { rewriteRun( - //language=xml - pomXml( - """ - - com.example - example-parent - 1.0.0 - 4.0 - - 11 - 11 - 11 - 11 - 11 - 11 - 11 - 11 - - - """, - SourceSpec::skip), - mavenProject("example-child", //language=xml pomXml( - """ - - - com.example - example-parent - 1.0.0 - - - - com.example - example-child - 1.0.0 - 4.0 - - """, - """ + """ + + com.example + example-parent + 1.0.0 + 4.0 + + 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 + + + """, + """ - - com.example - example-parent - 1.0.0 - - - com.example - example-child + example-parent 1.0.0 4.0 17 - 17 17 + 17 17 - 17 17 17 + 17 17 - """ + """), + mavenProject("example-child", + //language=xml + pomXml( + """ + + + com.example + example-parent + 1.0.0 + + com.example + example-child + 1.0.0 + 4.0 + + """ + ) ) - ) ); } @@ -270,7 +259,7 @@ void springBoot3ParentToJava17() { 3.3.3 - + com.mycompany.app my-app 1 @@ -295,7 +284,7 @@ void springBoot3ParentToJava21() { 3.3.3 - + com.mycompany.app my-app 1 @@ -311,7 +300,7 @@ void springBoot3ParentToJava21() { 3.3.3 - + com.mycompany.app my-app 1