如何解决获取Maven项目的所有依赖项
| 你好 有没有一种简单的方法可以使用java(而不是mvn控制台)获取maven项目的所有依赖关系,或者mvn中使用的算法是什么?谢谢 Ive找到了模型(org.apache.maven.model) 直到找到变量为止,下面的代码才有效(例如\'<\'version> $ {mavenVersion} \'<\'/ version>) System.out.println(\“ dependency \” + d.getArtifactId()); if(d.isOptional()){ 返回; } if(d.getVersion()== null){ if(mod.getParent()!= null){ 尝试{ MavenArtifact mart = new 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){ 对于(依赖关系Dep:fMod.getDependencyManagement()。getDependencies()){ if(dep.getArtifactId()。equals(d.getArtifactId())&dep.getGroupId()。equals(d.getGroupId())){ getDependency(fMod,mart,p,dep); } } 对于(依赖关系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(\“找不到: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()); 返回; } importMavenArtifact(m,p);解决方法
如果要匹配2.x的行为,请阅读maven-dependency-plugin的源代码。如果您需要匹配3.x,我认为您必须了解以太。
,尝试使用jcabi-aether,它是Aether的包装器。首先,您将需要获得所有项目依赖项的列表:
List<Artifact> deps = this.project.getDependencies();
然后,对于其中的每一个,您都可以获得所有传递依赖项的列表:
File repo = this.session.getLocalRepository().getBasedir();
Collection<Artifact> deps = new Aether(this.getProject(),repo).resolve(
new DefaultArtifact(\"junit\",\"junit-dep\",\"\",\"jar\",\"4.10\"),JavaScopes.RUNTIME
);
我可能在细节上是错误的,但是总的来说,这是应该的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。