我试图使用列出一些Maven工件的依赖项org.apache.maven.project.MavenProject
。
我的代码是这样的。
public List<Dependencies> loadProject() {
Model mavenModel = new Model();
mavenModel.setModelVersion("4.0.0");
mavenModel.setGroupId("org");
mavenModel.setArtifactId("wso2");
mavenModel.setVersion("1.0.0");
addDependency(mavenModel, "com.google.inject", "guice", "4.2.2");
addDependency(mavenModel, "ch.qos.logback", "logback-classic", "1.2.3");
MavenProject mavenProject = new MavenProject(mavenModel);
//******* Need to resolve dependencies of `mavenProject` and *******
//******* get the list of dependencies of this project. *******
return dependencies;
}
private static void addDependency(Model mavenModel, String groupId, String artifactId, String version) {
Dependency dependency = new Dependency();
dependency.setGroupId(groupId);
dependency.setArtifactId(artifactId);
dependency.setVersion(version);
mavenModel.addDependency(dependency);
}
基本上,我试图获取依存关系树结果,该结果mvn dependency:tree
以编程方式通过命令作为列表返回。
示例 对于工件:
com.google.inject:guide:4.2.2
ch.qos.logback:logback-classic:1.2.3
依赖项列表:
List = [
com.google.inject:guice:jar:4.2.2:compile,
javax.inject:javax.inject:jar:1:compile,
aopalliance:aopalliance:jar:1.0:compile,
com.google.guava:guava:jar:25.1-android:compile,
com.google.code.findbugs:jsr305:jar:3.0.2:compile,
org.checkerframework:checker-compat-qual:jar:2.0.0:compile,
com.google.errorprone:error_prone_annotations:jar:2.1.3:compile,
com.google.j2objc:j2objc-annotations:jar:1.1:compile,
org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile,
ch.qos.logback:logback-classic:jar:1.2.3:compile,
ch.qos.logback:logback-core:jar:1.2.3:compile,
org.slf4j:slf4j-api:jar:1.7.25:compile
]
Tunaki在stackoverflow.com/questions/39638138/上
—
Nikhil Zurunge
@NikhilZurunge但是在这里我不想通过创建pom文件来创建Maven项目。我要使用
—
Pramodya Mendis
org.apache.maven.project.MavenProject
该信息仅在maven构建期间可用,这意味着在maven插件的上下文中。如果你只是看你没有这些信息的POM文件....没有dependencyManagement的分辨率(如果使用的话)等等
—
khmarbaise
我想知道是否有任何Java方法或类可以解决
—
Pramodya Mendis
MavenProject
对象的依赖关系