嗨,有没有一种简单的方法可以让我使用 java(不是 mvn 控制台)或 mvn 中使用的算法获取 maven 项目的所有依赖项?谢谢
我找到了模型 (org.apache.maven.model) 下面的代码一直有效,直到找到一个变量(例如'<'version>${mavenVersion}'<'/version>)
System.out.println("依赖" + d.getArtifactId()); 如果(d.isOptional()){ 返回; } if(d.getVersion()==null){ 如果(mod.getParent()!=空){ 尝试{ MavenArtifact 市场=新的 MavenArtifact(); mart.setArtifactId(mod.getParent().getArtifactId()); mart.setGroupId(mod.getParent().getGroupId()); mart.setVersion(mod.getParent().getVersion()); mart.setRepositoryUrl(mA.getRepositoryUrl()); 模型 fMod = getModelFromPom(mart, p); if(fMod.getDependencyManagement()!=null){ for(依赖关系:fMod.getDependencyManagement().getDependencies()){ if(dep.getArtifactId().equals(d.getArtifactId())&dep.getGroupId().equals(d.getGroupId())){ getDependency(fMod, 市场, p, dep); } } for (依赖 dep : fMod.getDependencies()) { if(dep.getArtifactId().equals(d.getArtifactId())&dep.getGroupId().equals(d.getGroupId())){ getDependency(fMod, 市场, p, dep); } } }} 捕获(异常 e){ e.printStackTrace(); view.showWarning("找不到:groupId:" + d.getGroupId() + "artifactId" + d.getArtifactId() + "版本:" + d.getVersion()); } }别的{ view.showWarning("找不到:groupId:" + d.getGroupId() + "artifactId" + d.getArtifactId() + "版本:" + d.getVersion()); } }别的{ MavenArtifact m = proxy.findDependency(d.getGroupId(), d .getArtifactId(), d.getVersion()); 如果(m == null){ view.showWarning("找不到:groupId:" + d.getGroupId() + "artifactId" + d.getArtifactId() + "版本:" + d.getVersion()); 返回; } 进口MavenArtifact(m,p);