Skip to content

Conversation

@eric-milles
Copy link
Member

Inspect the DependencyDescriptorMediator objects of ModuleDescriptor to represent overrides in Maven's dependencyManagement element.

https://issues.apache.org/jira/browse/IVY-1653

@maartenc
Copy link
Contributor

I'm wondering what happens if you specify the organisation in the override, like in the example in the JIRA.
Will that give issues with the generated pom file? Will Maven be able to handle that?

@eric-milles
Copy link
Member Author

This test case does just that:

@maartenc
Copy link
Contributor

maartenc commented Aug 18, 2025

Sure, but how does Maven handle the '*' artifactId? Does that work?

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>*</artifactId>
  <version>1.9.24</version>
</dependency>

@eric-milles
Copy link
Member Author

I'd have to try that with maven. Is there a concern that lots of top-level overrides are in use? Could this get taken as-is and if we find a compatibility problem, work it as a new issue?

@maartenc
Copy link
Contributor

If maven gives errors on these wildcards, perhaps we could only add it to the dependencymanagement if the Ivy-override is fully specified (read: both groupId and artifactId have a non-wildcard value) ?
If maven doesn't complain about this wildcard, than we can just generate it like this PR does.

We should try to avoid generating pom.xml files that cannot be handled by Maven.

@eric-milles
Copy link
Member Author

[ERROR] 'dependencyManagement.dependencies.dependency.artifactId' for org.eclipse.tycho:*:jar with value '*' does not match a valid id pattern.

@eric-milles
Copy link
Member Author

I fixed the tests to write proper artifactId elements.

ModuleRules<DependencyDescriptorMediator> mr = md.getAllDependencyDescriptorMediators();
if (mr.getAllRules().isEmpty()) {
return;
}
Copy link
Contributor

@maartenc maartenc Aug 18, 2025

Choose a reason for hiding this comment

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

Perhaps also return here if none of the rules are an instance of non-wildcard OverrideDependencyDescriptorMediator.
This way, we avoid an empty <dependencyManagement>/<dependencies>-construct if container was true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure -- I tried to keep it simple instead of building up a filtered collection.

};

assertEquals(String.join(System.lineSeparator(), expect), readFileToString(pomFile, "UTF-8"));
}
Copy link
Contributor

@maartenc maartenc Aug 18, 2025

Choose a reason for hiding this comment

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

Could you also add a test case for updating a template pom.xml that already has a dependencyManagement section, and we have an ivy.xml with an override element. (just to verify that an existing dependencyManagent gets updated correctly).

public class IvyMakePomTest {

private Project project;
private Project project = TestHelper.newProject();
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't the same as creating a new project in a @before method.
Now, the same project is reused for every IvyMakePom task in the test methods.
Before, every task had a new project.
I'm not saying this is a problem per se, but why change it? Did it cause issues?

Copy link
Member Author

@eric-milles eric-milles Aug 18, 2025

Choose a reason for hiding this comment

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

In JUnit 4, a new instance of the test class is created for each test case. You are describing the JUnit 3 behavior.

org.apache.ivy.plugins.pack;version="2.6.0",
org.apache.ivy.plugins.parser;version="2.0.0",
org.apache.ivy.plugins.parser.m2;version="2.0.0",
org.apache.ivy.plugins.parser.m2;version="2.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiousity, is this Eclipse that's doing this for you?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am doing this. If you look at the 2.5.3 manifest, all the versions are stuck at 2.0.0 which is not really proper for OSGi.

dependenciesPrinted = true;
}
if (line.contains("</dependencyManagement>")) {
dependencyManagement = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should also check here that any overrides are printed.
This to tackle the case where the template contains an empty <dependencyManagent> element (without <dependencies> subelement)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I suppose that's possible. Was just handling likely scenarios first.

@maartenc
Copy link
Contributor

I've added some comments, could you have a look?

@eric-milles
Copy link
Member Author

I will get to your feedback on this one. Now that <override org="abc" rev="123" /> doesn't work, this drops in usefulness for me.

@eric-milles
Copy link
Member Author

Could you review my PRs from oldest to newest?

@eric-milles eric-milles marked this pull request as draft September 3, 2025 18:01
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.

2 participants