嗨 有没有一种简单的方法,我可以得到所有依赖关系的Maven项目使用Java(而不是mvn控制台)或什么是在mvn中使用的算法?感谢得到一个Maven项目的所有依赖关系
伊夫发现模型(org.apache.maven.model) 下面的代码工作,直到它找到一个变量(例如 '< '版本> $ {mavenVersion}' <'/版本>)
System.out.println("dependency" + d.getArtifactId()); if(d.isOptional()){ return; } if(d.getVersion()==null){ if(mod.getParent()!=null){ try{ MavenArtifact mart=new MavenArtifact(); mart.setArtifactId(mod.getParent().getArtifactId()); mart.setGroupId(mod.getParent().getGroupId()); mart.setVersion(mod.getParent().getVersion()); mart.setRepositoryUrl(mA.getRepositoryUrl()); Model fMod = getModelFromPom(mart, p); if(fMod.getDependencyManagement()!=null){ for (Dependency dep : fMod.getDependencyManagement().getDependencies()) { if(dep.getArtifactId().equals(d.getArtifactId())&dep.getGroupId().equals(d.getGroupId())){ getDependency(fMod, mart, p, dep); } } for (Dependency dep : fMod.getDependencies()) { if(dep.getArtifactId().equals(d.getArtifactId())&dep.getGroupId().equals(d.getGroupId())){ getDependency(fMod, mart, p, dep); } } }} catch(Exception e){ e.printStackTrace(); view.showWarning("Could not find: groupId:" + d.getGroupId() + " artifactId" + d.getArtifactId() + " version:" + d.getVersion()); } }else{ view.showWarning("Could not find: groupId:" + d.getGroupId() + " artifactId" + d.getArtifactId() + " version:" + d.getVersion()); } }else{ MavenArtifact m = proxy.findDependency(d.getGroupId(), d .getArtifactId(), d.getVersion()); if (m == null) { view.showWarning("Could not find: groupId:" + d.getGroupId() + " artifactId" + d.getArtifactId() + " version:" + d.getVersion()); return; } importMavenArtifact(m, p);
看起来不错,但我无法测试它,因为我的项目被遗弃+1 – sherif 2012-10-28 20:41:37