desruisseaux commented on issue #11602:
URL: https://github.com/apache/maven/issues/11602#issuecomment-3693912462
In my understanding, the whole `org.apache.maven.project.MavenProject` class
is deprecated, even if it does not yet have the `@Deprecated` annotation (maybe
because it is still used internally by Maven). It is replaced by
`org.apache.maven.api.Project`. For getting the dependencies, you can use:
```java
import org.apache.maven.api.PathScope;
import org.apache.maven.api.PathType;
import org.apache.maven.api.Project;
import org.apache.maven.api.Session;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.plugin.Mojo;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.services.DependencyResolver;
import org.apache.maven.api.services.DependencyResolverRequest;
import org.apache.maven.api.services.DependencyResolverResult;
class MyMojo implements Mojo {
@Inject
private Session session;
@Inject
private Project project;
@Override
public void execute() throws MojoException {
DependencyResolver resolver =
session.getService(DependencyResolver.class);
DependencyResolverResult dependencies =
resolver.resolve(DependencyResolverRequest.builder()
.session(session)
.project(project)
.requestType(DependencyResolverRequest.RequestType.RESOLVE)
.pathScope(PathScope.MAIN_RUNTIME)
.pathTypeFilter(EnumSet.of(JavaPathType.CLASSES,
JavaPathType.MODULES))
.build());
// Skipping `dependencies.getExceptions()` for simplicity, but it
should be verified in real applications.
Map<PathType, List<Path>> dependencies.getDispatchedPaths();
}
}
```
A key point is that we need to specify in which paths we are interested:
class-path, module-path, processor-path, doclet-path, taglet-path, etc. Above
example filter the dependencies for the class-path and module-path. Then, the
result is a map with the key (the `PathType`) telling whether the files should
be placed on the class-path or on the module-path.
A problem of the old deprecated method is that it totally ignores this
class-path versus module-path issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]