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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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",
  },
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support maven variables for package replacements
2 participants