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

NPE in DependenciesTool when running aggregateAddThirdParty with excludeTransitiveDependencies set to true #310

Open
srdo opened this issue Mar 25, 2019 · 3 comments

Comments

@srdo
Copy link
Contributor

srdo commented Mar 25, 2019

I'm getting an NPE in DependenciesTool.loadProjectDependencies.

The issue seems to be that loadProjectDependencies assumes that all artifacts have a non-null dependency trail.

The artifacts are loaded in loadProjectArtifacts, where reactor projects are excluded as we can't expect Maven to correctly resolve artifacts for projects that may not have been built yet. The method instead replaces reactor projects with their direct dependencies in order to still get the full dependency tree. It then resolves all dependencies except reactor projects. When the dependency lists are returned, the reactor artifacts are included but not fully populated.

I'm not sure what the best fix is here. Maybe loadProjectArtifacts shouldn't return reactor projects at all? I'm not sure why we would want to return reactor projects from that method.

Caused by: java.lang.NullPointerException
    at org.codehaus.mojo.license.api.DependenciesTool.loadProjectDependencies (DependenciesTool.java:243)
    at org.codehaus.mojo.license.api.DefaultThirdPartyHelper.loadDependencies (DefaultThirdPartyHelper.java:156)
@ppalaga
Copy link
Contributor

ppalaga commented Mar 25, 2019

An integration test in https://github.com/mojohaus/license-maven-plugin/tree/master/src/it reproducing the issue would be highly welcome.

@srdo
Copy link
Contributor Author

srdo commented Mar 25, 2019

I have the relevant bit of an integration test ready at https://github.com/srdo/license-maven-plugin/tree/issue-310/src/it/ISSUE-310. The test isn't done (the assertion and README are wrong), but it provokes the error.

I think the best way to fix this would be to sidestep the issue and get rid of the excludeTransitiveDependencies parameter. As far as I can tell, the idea is that if you have a project

A -> B -> C

and you exclude B, the plugin should also exclude C.

The dependencyTrail seems to be a bad way to accomplish what that parameter is trying to do. https://issues.apache.org/jira/browse/MNG-4831 has an example project that is basically

A -> C
B -> C
D -> A & B

where the issue becomes what should the plugin do if you ask it to exclude A plus transitive deps? We might get a dependencyTrail that is D -> A -> C, in which case C will be excluded, but we might also get a trail D -> B -> C, in which case it isn't.

It would be better if we could filter artifacts out during dependency resolution. That way, if you exclude e.g. A, that part of the dependency tree simply won't be resolved. This would be equivalent to having excludeTransitiveDependencies always be true, but I'm not sure there's a use case for having it be false?

Tibor was talking about upgrading the project here #219 and the newer artifact resolver API lets you set a filter on resolution requests https://maven.apache.org/resolver/apidocs/org/eclipse/aether/resolution/DependencyRequest.html. It might be worth looking at upgrading to using that resolver?

@ppalaga
Copy link
Contributor

ppalaga commented Mar 27, 2019

It would be better if we could filter artifacts out during dependency resolution.

I think that would be nice for performance reasons too.

excludeTransitiveDependencies always be true

In case there is no way to keep excludeTransitiveDependencies working in a backwards compatible way, we'd have to release that as a new major version (which I am not against).

Please go ahead and try your idea.

cc @Tibor17

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

No branches or pull requests

2 participants