를 사용하여 일부 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
]