Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/maven): Support variables for package replacements #34359

Conversation

jonasrutishauser
Copy link
Contributor

Changes

This should fix maven replacements if a shared variable name is in use.

Context

Closes #34088

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to make a significant change to results, including possibly adding duplicates, which seems unrelated to replacements

@jonasrutishauser
Copy link
Contributor Author

This seems to make a significant change to results, including possibly adding duplicates, which seems unrelated to replacements

That's correct, but if a property is used multiple times, there may be already duplicates.
I think it will even improve the display of dependencies, as the real dependency location is added too.

Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test changes show a lot of duplicate results, which is undesirable at best and potentially causes problems. Sorry but this solution is not acceptable

@jonasrutishauser
Copy link
Contributor Author

jonasrutishauser commented Feb 24, 2025

Just an example of a simple project with the following pom files:
pom.xml

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0</version>
  <properties>
    <test.version>1.2.3</test.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.example</groupId>
      <artifactId>test</artifactId>
      <version>${test.version}</version>
    </dependency>
  </dependencies>
  <modules>
    <module>foo</module>
    <module>bar</module>
  </modules>
</project>

foo/pom.xml

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>foo</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.example</groupId>
      <artifactId>test</artifactId>
      <version>${test.version}</version>
    </dependency>
  </dependencies>
</project>

bar/pom.xml

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>bar</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.example</groupId>
      <artifactId>test</artifactId>
      <version>${test.version}</version>
    </dependency>
  </dependencies>
</project>

The existing code gives the following:

Array [
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
    ],
    "packageFile": "pom.xml",
    "packageFileVersion": "1.0.0",
  },
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.0.0",
        "datasource": "maven",
        "depName": "org.example:parent",
        "depType": "parent-root",
        "fileReplacePosition": 142,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
      },
    ],
    "packageFile": "foo/pom.xml",
  },
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.0.0",
        "datasource": "maven",
        "depName": "org.example:parent",
        "depType": "parent-root",
        "fileReplacePosition": 142,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
      },
    ],
    "packageFile": "bar/pom.xml",
  },
]

We can see that the dependency org.example:test is shown 3 times at the same location (the property in the root pom).
It therefore already contains duplicates and won't show the correct dependency location. It even is impossible this way to replace the source groupId and/or artifactId.

With the proposed change the source <dependency> elements will be additionally added which gives some more duplicates of the same dependency, but also adds the real location of the dependencies.

Array [
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "fileReplacePosition": 333,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 174,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
    ],
    "packageFile": "pom.xml",
    "packageFileVersion": "1.0.0",
  },
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.0.0",
        "datasource": "maven",
        "depName": "org.example:parent",
        "depType": "parent-root",
        "fileReplacePosition": 142,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 323,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
    ],
    "packageFile": "foo/pom.xml",
  },
  Object {
    "datasource": "maven",
    "deps": Array [
      Object {
        "currentValue": "1.0.0",
        "datasource": "maven",
        "depName": "org.example:parent",
        "depType": "parent-root",
        "fileReplacePosition": 142,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
      },
      Object {
        "currentValue": "1.2.3",
        "datasource": "maven",
        "depName": "org.example:test",
        "depType": "compile",
        "editFile": "pom.xml",
        "fileReplacePosition": 323,
        "registryUrls": Array [
          "https://repo.maven.apache.org/maven2",
        ],
        "sharedVariableName": "test.version",
      },
    ],
    "packageFile": "bar/pom.xml",
  },
]

@rarkins rarkins added the auto:discussion-first This PR needs to be preceded by a GitHub Discussion label Mar 9, 2025
Copy link
Contributor

github-actions bot commented Mar 9, 2025

Please create a GitHub Discussion before continuing with this PR.

Thank you for your PR, but we need to discuss the requirements and implementation first.

The maintainers believe that there is a lack of - or misalignment of - requirements about this PR. We need to discuss the requirements and implementation first so that you don't write code that won't be merged.

This PR will be closed for now to avoid confusion, but you can reopen it after the discussion has been resolved.

Thanks, the Renovate team

@github-actions github-actions bot closed this Mar 9, 2025
@rarkins
Copy link
Collaborator

rarkins commented Mar 9, 2025

Let's discuss this in a Discussion instead. Duplicating extract values is highly undesirable

@jonasrutishauser
Copy link
Contributor Author

Discussion started in #34755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:discussion-first This PR needs to be preceded by a GitHub Discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support maven variables for package replacements
2 participants