我正在尝试创建一个maven 3插件,该插件应解析项目的每个依赖项和传递性依赖项,并列出工件,最好列出本地maven存储库中的jar文件的链接。我运气不好。
此后,我必须处理依赖关系,因为依赖关系和树插件并不是我真正的选择。我需要创建一个可以处理依赖工件的自定义插件。
我尝试使用DependencyGraphBuilder创建插件,但没有成功:
@Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true)
private File outputDirectory;
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
@Component(hint = "maven3")
private DependencyGraphBuilder dependencyGraphBuilder;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File targetDir = outputDirectory;
if (!targetDir.exists()) {
targetDir.mkdirs();
}
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProject(project);
try {
try (PrintWriter writer = new PrintWriter(new File(outputDirectory, "output"))) {
writer.println("I did shit");
}
DependencyNode depenGraphRootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, null);
CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
depenGraphRootNode.accept(visitor);
List<DependencyNode> children = visitor.getNodes();
for (DependencyNode node : children) {
System.out.println(node.getArtifact().getGroupId() + " " + node.getArtifact().getArtifactId());
try (PrintWriter writer = new PrintWriter(new File(outputDirectory, "output"))) {
writer.println(node.getArtifact().getGroupId() + " " + node.getArtifact().getArtifactId());
}
}
} catch (Exception ex) {
}
}
例如,根据我pom中的依赖版本,我有一些不同的例外情况
java.lang.NoSuchMethodError:org.apache.maven.artifact.versioning.DefaultArtifactVersion.compareTo(Lorg / apache / maven / artifact / versioning / ArtifactVersion;)I
和
java.lang.NoClassDefFoundError:org / eclipse / aether / RepositorySystemSession
有人可以为我提供一个有效的依赖项设置,以使DependencyGraphBuilder正常工作吗,或者以其他方式解析编译项目的依赖项?