我的目标是开发一个用于工件部署的内部工具。工件位于本地存储库管理系统(sonatype nexus)中。经过研究,我尝试使用 Aether-Api 来实现该任务。但是我无法自己重新编程他们的一个例子。我无法评估错误。
public class SourceMaven
{
private static RepositorySystem newRepositorySystem()
{
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
return locator.getService(RepositorySystem.class);
}
private static RepositorySystemSession newSession(RepositorySystem system)
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository("/usr/local/home/myusername/tmp/aether");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
return session;
}
private static List<RemoteRepository> newRepositories( RepositorySystem system, RepositorySystemSession session)
{
return new ArrayList<RemoteRepository>(Arrays.asList(newCentralRepository()));
}
private static RemoteRepository newCentralRepository()
{
return new RemoteRepository.Builder("sonanexus", "default", "http://ournexusservername:8081/nexus/#nexus").build();
}
public List<String> getReleaseList(String url)
{
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newSession(system);
Artifact artifact = new DefaultArtifact("org.eclipse.aether:aether-util:[0,)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(newRepositories(system, session));
try
{
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
List<Version> versions = rangeResult.getVersions();
System.out.println("available versions " + versions);
}
catch (VersionRangeResolutionException ex)
{
System.out.println("failed ...");
}
return null;
}
}
作为输出,我只得到一个空列表而没有错误。
可用版本 []
请求的工件坐标在我们的关系中链接,可以在网络界面中找到。