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

Support ordering of dependencies #181

Open
gastaldi opened this issue Nov 3, 2020 · 9 comments · May be fixed by #182
Open

Support ordering of dependencies #181

gastaldi opened this issue Nov 3, 2020 · 9 comments · May be fixed by #182

Comments

@gastaldi
Copy link

gastaldi commented Nov 3, 2020

After the pom.xml's dependencies are flattened, it would be nice if the plugin allowed you to order the dependencies (to make it easier to read).

gastaldi added a commit to gastaldi/flatten-maven-plugin that referenced this issue Nov 3, 2020
@lasselindqvist
Copy link
Collaborator

Is this a way to keep the original order for you? Or do you use this to order them only in the flattened pom?

@gastaldi
Copy link
Author

gastaldi commented Nov 4, 2020

This is a way to order only in the flattened pom

@lasselindqvist
Copy link
Collaborator

Not sure how necessary this is then. I would recommend keeping them in order in the original pom and flatten plugin could enforce the source ordering.
So on the other hand I wouldn't want too many parameters that bring only a little value, but then again it does bring some value.

@lasselindqvist
Copy link
Collaborator

So I checked and the order of dependencies matters for transitive dependencies. (https://stackoverflow.com/questions/31740785/why-order-of-maven-dependencies-matter/31743617#31743617)
This ordering might in these cases cause problems that are hard to debug.

So I would say that the order needs to stay the same. I think it already does even though I could not find a proper test for it (https://github.com/mojohaus/flatten-maven-plugin/tree/master/src/it/projects)

Because ordering can change the behaviour of the pom, I would not merge this.

@gastaldi
Copy link
Author

gastaldi commented Nov 5, 2020

@lasselindqvist The Maven resolution algorithm resolves transient dependencies' versions based on the root proximity of the pom.xml dependency tree. That's why the original pom should NEVER order dependencies, but when talking about flattened poms (which all dependencies are in the same level) the order doesn't really matter.

@lasselindqvist
Copy link
Collaborator

It uses the distance to decide the candidates, but if two transitive dependencies have the same distance, it takes the one that it first.
And the order does matter, because this plugin can and is used to deploy flattened poms to repositories and then used in other projects.

@gastaldi
Copy link
Author

gastaldi commented Nov 5, 2020

I am probably missing something, but how can you have transitive dependencies in a flattened pom? Anyway, feel free to close this PR and the issue if you think it doesn't make sense.

Thanks for the feedback!

@lasselindqvist
Copy link
Collaborator

http://www.mojohaus.org/flatten-maven-plugin/flatten-mojo.html#flattenDependencyMode
flattenDependencyMode affects transitive dependencies differently
So the direct mode might for example just resolve the version numbers of direct dependencies from properties, but the "all" mode would bring new nodes to the visible tree in the file.
Then there is also the flattenMode, and in case of for example resolveCiFriendliesOnly, the dependencies might be left completely untouched.

Now, I don't want to reject it just yet, because it might make sense to merge it, have it off by default (as it is in the open PR) and have a clear warning in the documentation about the risk of using it.

I'd like to leave this issue open for a while to see if some third person has opinion or arguments for or against.

@slawekjaranowski slawekjaranowski linked a pull request Aug 7, 2022 that will close this issue
@F1ncyJ
Copy link

F1ncyJ commented Aug 13, 2024

I agree, sorting is not just about affecting the final decision on Maven dependencies; from a learning, reading, and management perspective, I would like to keep the order of tags within the POM file after flattening.

Additionally, I found that even with the "keepCommentsInPom" feature enabled, multi-level comment structures are flattened and destroyed.

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 a pull request may close this issue.

3 participants