Hello everybody,
before deploying some artifacts via the Eclipse Aether API to my Nexus Release Repository, I try to check if they are already present to avoid a "400 Bad Request" error. With the following set-up methods
public 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);
}
public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system)
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository("target/local-repo");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
session.setTransferListener(new ConsoleTransferListener());
session.setRepositoryListener(new ConsoleRepositoryListener());
return session;
}
I tried the following:
private boolean existArtifactInRepository(final Artifact artifact, final RemoteRepository repository)
{
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(Collections.singletonList(repository));
try
{
RepositorySystem system = newRepositorySystem();
ArtifactResult result = system.resolveArtifact(newRepositorySystemSession(system), request);
return result.isResolved();
}
catch (ArtifactResolutionException e)
{
return false;
}
}
Unfortunately, the resolving always fails with the complaint that no transport connector has been set to access my repository. The repository is a standard Maven release repository on a Nexus repository manager accessible via the HTTP protocol. And uploading artifacts works if I use the injected repository system and session. However, in my use case I cannot use the same repository system and session for checking the existence since I am in a reactor build and this will always resolve the artifacts in question - even though they are definitely not contained in the nexus repo.