Skip to content

UpgradeDependencyVersion with overrideManagedVersion does not add property if <relativePath> is missing #6945

@Goshenkata

Description

@Goshenkata

Adding this test case in UpgradeDependencyVersionTests fails - the recipe makes no changes

    @Test
    void upgradeVersionDefinedViaImplicitPropertyInRemoteParentOfLocalParent_withoutRelativePath() {
        rewriteRun(
          spec -> spec.recipe(new UpgradeDependencyVersion("org.flywaydb", "flyway-core", "10.15.0", "", true, null)),
          pomXml(
            """
              <project>
                  <parent>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-dependencies</artifactId>
                      <version>3.3.0</version>
                  </parent>
                  <groupId>com.mycompany</groupId>
                  <artifactId>my-parent</artifactId>
                  <version>1</version>
                  <dependencies>
                      <dependency>
                          <groupId>org.flywaydb</groupId>
                          <artifactId>flyway-core</artifactId>
                      </dependency>
                  </dependencies>
              </project>
              """,
            """
              <project>
                  <parent>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-dependencies</artifactId>
                      <version>3.3.0</version>
                  </parent>
                  <groupId>com.mycompany</groupId>
                  <artifactId>my-parent</artifactId>
                  <version>1</version>
                  <properties>
                      <flyway.version>10.15.0</flyway.version>
                  </properties>
                  <dependencies>
                      <dependency>
                          <groupId>org.flywaydb</groupId>
                          <artifactId>flyway-core</artifactId>
                      </dependency>
                  </dependencies>
              </project>
              """
          ),
          mavenProject("my-child",
            pomXml(
              """
                <project>
                    <parent>
                        <groupId>com.mycompany</groupId>
                        <artifactId>my-parent</artifactId>
                        <version>1</version>
                    </parent>
                    <groupId>com.mycompany</groupId>
                    <artifactId>my-child</artifactId>
                    <version>1</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.flywaydb</groupId>
                            <artifactId>flyway-core</artifactId>
                        </dependency>
                    </dependencies>
                </project>
                """
            )
          )
        );
    }

The root cause is AddProperty where the is this check

// If there is a parent pom in the same project, update the property there instead
                if (document.getRoot().getChild("parent")
                        .flatMap(tag -> tag.getChild("relativePath"))
                        .flatMap(Xml.Tag::getValue)
                        .flatMap(v -> v.trim().isEmpty() ? Optional.empty() : Optional.of(v))
                        .isPresent()

However relativePath can be ommited and then it's implicitly "../pom.xml" a more proper check could be:

if (getResolutionResult().parentPomIsProjectPom())

But this breaks some callers of the AddProperty.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions