Skip to content

Conversation

@rfscholte
Copy link
Contributor

@rfscholte rfscholte commented Dec 29, 2025

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@rfscholte rfscholte requested a review from mthmulders December 29, 2025 12:36
List<RemoteRepository> remoteRepositories =
RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories());

Collection<org.eclipse.aether.artifact.Artifact> depArtifacts =
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify: we do full (transitive) dependency resolution only when the user specified one or more graphRoots, but not when the project itself is the graphRoot. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The project dependencies have already been resolved, as the goal of the final Mojo contains requiresDependencyResolution = ResolutionScope.TEST. So it is actually re-resolving the dependencies. The MavenProject doesn't provide the graph, hence the need ask for the graph user maven artifact resolver.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get it. Maybe worth copying that text to an inline comment, in order to prevent future maintainers from asking themselves why the code is there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

package org.apache.maven.plugins.dependency.fromDependencies;

/**
* All values are static, no expression, so matcher can use equals
Copy link
Contributor

Choose a reason for hiding this comment

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

But the matcher does not use equals()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good question. My first approach was to make these values Nullable: if not specified it is a match. However while working with it (and as confirmed in the integration-test) it is probably better to be explicit. Just always specify groupId and artifactId, and type if it is not a jar, just as explicit as the dependency. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would certainly prefer to make it explicit, and not give null the magical meaning of "could be anything" or "don't care".

Just always specify groupId and artifactId, and type if it is not a jar, just as explicit as the dependency.

You mean: actual matching is as explicit as the graphRoot declaration in the plugin configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A small rewrite, you know must define the graphRoot's groupId and artifactId matching the targeted dependency. I've removed the type, because only the main artifact can have dependencies (classified like javadoc and sources don't have dependencies) and the pom can only point to 1 main artifact via packaging. I don't expect a request for support of type, but if so it should be solved separately. It is probably tricky if 2 main artifacts share the same pom.


@Override
public boolean matches(Dependency dependency) {
return matches(graphRoot.getGroupId(), dependency.getGroupId())
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 could've used Objects.equals() here - it's available since Java 1.7, according to its Javadoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous comment. If graphroot is explicit, this matches can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've decided to keep this class, as we're trying to match 2 different kind of classes. null-ignoring matches method has been replaced.


import org.apache.maven.model.Dependency;

class OrDependencyMatcher implements DependencyMatcher {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I would've added unit tests for this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


import org.apache.maven.model.Dependency;

class GraphRootMatcher implements DependencyMatcher {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I would've added unit tests for this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @since 3.10.0
*/
@Parameter
private List<GraphRoot> graphRoots;
Copy link
Member

Choose a reason for hiding this comment

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

As GraphRoot is an complex object we can provide an example in documentation to be clear how to use in configuration

root, session.getRepositorySession().getArtifactTypeRegistry());

List<RemoteRepository> remoteRepositories =
RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories());
Copy link
Member

Choose a reason for hiding this comment

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

There is MavenProject#getRemoteProjectRepositories

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.

3 participants