@Requirement
private RepositorySystem repoSystem;
@Override
public File resolve(final MavenProject project, final String artifact) {
final ArtifactResult result;
try {
ProjectBuildingRequest projectBuildingRequest = invoke(project, "getProjectBuildingRequest", ProjectBuildingRequest.class);
final ArtifactRequest request = new ArtifactRequest();
final DefaultArtifact defaultArtifact = createArtifact(artifact);
request.setArtifact(defaultArtifact);
@SuppressWarnings("unchecked")
final List<RemoteRepository> repos = invoke(project, "getRemoteProjectRepositories", List.class);
request.setRepositories(repos);
result = repoSystem.resolveArtifact(invoke(projectBuildingRequest, "getRepositorySession", RepositorySystemSession.class), request);
} catch (ArtifactResolutionException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result.getArtifact().getFile();
}