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

[MNG-7619] Reverse Dependency Tree #900

Merged

Conversation

cstamas
Copy link
Member

@cstamas cstamas commented Dec 3, 2022

Adds Maven feature that is able to explain why an artifact is present in local repository.

Usable for diagnosing resolution issues.

In local repository, for each artifact it records .tracking folder, containing farthest artifact that got to this artifact, and the list of graph nodes that lead to it.

Note: this is based on by @grgrzybek proposal and reuses some code he provided. See apache/maven-resolver#182


https://issues.apache.org/jira/browse/MNG-7619

Adds Maven feature that is able to explain why an artifact
is present in local repository.

Usable for diagnosing resolution issues.

---

https://issues.apache.org/jira/browse/MNG-7619
@cstamas cstamas self-assigned this Dec 3, 2022
@cstamas
Copy link
Member Author

cstamas commented Dec 3, 2022

Excercise: build this PR (will produce Maven 3.9.0-SNAPSHOT distro), then use same distro to build itself (or just maven.3.9.x, does not matter) using these:

mvn clean install -Dmaven.repo.local=local -Dmaven.repo.local.recordReverseTree -Drat.skip

(rat is dumb to inspect "local" where local repository is and fail, so we skip it).

Q1: why is maven-core 2.2.1 in local repo?

[cstamas@infinity maven (maven-3.9.x  %)]$ tree -L 1 local/org/apache/maven/maven-core/2.2.1/.tracking/
local/org/apache/maven/maven-core/2.2.1/.tracking/
├── org.apache.maven.plugins_maven-remote-resources-plugin_jar_1.7.0
├── org.codehaus.mojo_build-helper-maven-plugin_jar_1.12
└── org.codehaus.mojo_buildnumber-maven-plugin_jar_1.4

0 directories, 3 files
[cstamas@infinity maven (maven-3.9.x  %)]$ cat local/org/apache/maven/maven-core/2.2.1/.tracking/org.codehaus.mojo_build-helper-maven-plugin_jar_1.12 
org.apache.maven:maven-core:jar:2.2.1 (compile) (plugin)
  org.codehaus.mojo:build-helper-maven-plugin:jar:1.12 () (plugin)
[cstamas@infinity maven (maven-3.9.x  %)]$

Q2: how many commons-codec we used and why?

[cstamas@infinity maven (maven-3.9.x %)]$ tree -L 1 local/commons-codec/commons-codec/
local/commons-codec/commons-codec/
├── 1.11
└── 1.15

2 directories, 0 files
[cstamas@infinity maven (maven-3.9.x %)]$ tree -L 1 local/commons-codec/commons-codec/1.15/.tracking/
local/commons-codec/commons-codec/1.15/.tracking/
└── org.apache.maven.plugins_maven-enforcer-plugin_jar_3.1.0

0 directories, 1 file
[cstamas@infinity maven (maven-3.9.x %)]$ tree -L 1 local/commons-codec/commons-codec/1.11/.tracking/
local/commons-codec/commons-codec/1.11/.tracking/
├── org.apache.maven_apache-maven_pom_3.9.0-SNAPSHOT
├── org.apache.maven_maven-resolver-provider_jar_3.9.0-SNAPSHOT
├── org.apache.maven.plugins_maven-checkstyle-plugin_jar_3.2.0
├── org.apache.maven.plugins_maven-dependency-plugin_jar_3.3.0
├── org.apache.maven.plugins_maven-site-plugin_jar_3.12.1
└── org.apache.rat_apache-rat-plugin_jar_0.15

0 directories, 6 files
[cstamas@infinity maven (maven-3.9.x %)]$ cat local/commons-codec/commons-codec/1.11/.tracking/org.apache.maven.plugins_maven-dependency-plugin_jar_3.3.0 
commons-codec:commons-codec:jar:1.11 (compile) (plugin)
  org.apache.httpcomponents:httpclient:jar:4.5.13 (compile) (plugin)
    org.apache.maven.doxia:doxia-core:jar:1.11.1 (compile) (plugin)
      org.apache.maven.reporting:maven-reporting-impl:jar:3.1.0 (compile) (plugin)
        org.apache.maven.plugins:maven-dependency-plugin:jar:3.3.0 () (plugin)
[cstamas@infinity maven (maven-3.9.x %)]$ 

@cstamas cstamas marked this pull request as ready for review December 3, 2022 21:19
@cstamas cstamas added this to the 3.9.0 milestone Dec 3, 2022
@cstamas
Copy link
Member Author

cstamas commented Dec 3, 2022

Note: this is based on by @grgrzybek proposal and reuses some code he provided. See apache/maven-resolver#182

@michael-o
Copy link
Member

Can we leave out these empty parens: org.apache.maven.plugins:maven-dependency-plugin:jar:3.3.0 () (plugin)? From a user PoV it looks like a bug.

@cstamas
Copy link
Member Author

cstamas commented Dec 3, 2022

Thats org.eclipse.aether.graph.Dependency#toString, we could fix it, but given this is "advanced" feature, I don't think is something would block this?

@michael-o
Copy link
Member

Thats org.eclipse.aether.graph.Dependency#toString, we could fix it, but given this is "advanced" feature, I don't think is something would block this?

Agree, we need to spin off the issue there. Here, no change is required.

@laeubi
Copy link

laeubi commented Dec 4, 2022

Not sure if this was already mentioned, but instead of "bake this in" would it not be better to have a way for (core-)plugins to hook in a RepositoryListener or even on the project level as we already to for AbstractMavenLifeCycleListeners / WorkspaceReaders? The this can become part of m-dependency-p for example.

I also wonder if it is even required to record the data at all, should it not be sufficient to first load the pom(s), then generate a list of used plugins and then resolve their dependencies and then do something similar to dependency:tree (maybe plugin-dependency-tree)? To make it more convenient then one might pass a -DdependencyReverse=<GAV> to have a reverse output rooted at the given GAV when build finished.

@cstamas
Copy link
Member Author

cstamas commented Dec 4, 2022

@laeubi while I agree with ideas you wrote, I am still for this PR to go in, here is why:
This PR is (nearly) trivial, but gives you powerful tool (for investigation, answering several questions), is registered early (earliest possible), and does not prevent anything of those you wrote (a plugin). Moreover, by being earliest present, and present during whole session of a real build, it covers everything (even extensions in bootstrap, and even some plugin that may dynamically resolve). Not easily done with something like build extension or even plugin (they are all too late to cover everything).

Also, none of these prevents anything of those things you wrote, this is totally orthogonal. I personally see this like -X for resolver, a handy switch seldom used by users, but when one needs it, is very very handy.

.getFile()
.getPath()
.startsWith(event.getSession().getLocalRepository().getBasedir().getPath())) {
return; // reactor artifact
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this condition be extracted to method IDK, isReactorArtifact(event)?
The comment then removed?
The method tested?

return; // reactor artifact
}
RequestTrace trace = event.getTrace();
CollectStepData collectStepTrace = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this variable be moved one line up, and the loop then extracted to (tested) class method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Class method (static) would need no instance for test. Like it doesn't to do its job.

@cstamas cstamas requested review from pzygielo and michael-o and removed request for pzygielo December 4, 2022 12:32
@cstamas
Copy link
Member Author

cstamas commented Dec 4, 2022

Um, unsure why GH says "removed request" from @pzygielo , I actually asked both @michael-o and @pzygielo for repeated review...

cstamas added a commit to cstamas/maven that referenced this pull request Dec 4, 2022
Adds Maven feature that is able to explain why an artifact is present in local repository.

Usable for diagnosing resolution issues.

In local repository, for each artifact it records `.tracking` folder, containing farthest artifact that got to this artifact, and the list of graph nodes that lead to it.

Note: this is based on by @grgrzybek proposal and reuses some code he provided. See apache/maven-resolver#182

Forward-port of: apache#900

---

https://issues.apache.org/jira/browse/MNG-7619
@cstamas cstamas merged commit 69c5a5d into apache:maven-3.9.x Dec 5, 2022
@cstamas cstamas deleted the maven-3.9.x-MNG-7619-reverse-dep-tree branch December 5, 2022 15:19
@gnodet gnodet mentioned this pull request May 24, 2023
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.

4 participants