Quantcast

Resolve dependencies inside a Nexus Plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Resolve dependencies inside a Nexus Plugin

Oscar Picasso-4
Hi,

I am writing a Nexus Plugin that would record all the transitive dependencies of any deployed artifact. I have some trouble to get the dependencies properly resolved.

Here are the pending problems I have:
  1. It does not resolve always to the latest SNAPSHOT dependencies. 
  2. I don't see how to get dependencies that have a classifier.
  3. How to get the scope of a dependency like when you use mvn dependency:tree?
I have tried different things. The closer to what I want is like code below, but this does not solve the problems above.

GavCalculator calculator = mavenRepository.getGavCalculator();
Gav gav = calculator.pathToGav(path);
Dependency dependency = Utils.createDependencyFromGav(gav, null);

CollectRequest collectRequest = new CollectRequest(dependency,
repositories);

DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest, null);
DependencyResult result = getRepositorySystem()
.resolveDependencies(getRepositorySession(), dependencyRequest);
List<ArtifactResult> artifactResults = result
.getArtifactResults();

Any pointer?
At this stage point 1 is the more important.

Oscar Picasso
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Resolve dependencies inside a Nexus Plugin

mgainty
Buenas Oscar

mavenRepository?
repositories?
getRepositories()?
getRepositorySession()?
nexus-indexer version?

Saludos!


Date: Mon, 28 Apr 2014 08:55:33 -0400
From: [hidden email]
To: [hidden email]
Subject: [nexus-dev] Resolve dependencies inside a Nexus Plugin

Hi,

I am writing a Nexus Plugin that would record all the transitive dependencies of any deployed artifact. I have some trouble to get the dependencies properly resolved.

Here are the pending problems I have:
  1. It does not resolve always to the latest SNAPSHOT dependencies. 
  2. I don't see how to get dependencies that have a classifier.
  3. How to get the scope of a dependency like when you use mvn dependency:tree?
I have tried different things. The closer to what I want is like code below, but this does not solve the problems above.

GavCalculator calculator = mavenRepository.getGavCalculator();
Gav gav = calculator.pathToGav(path);
Dependency dependency = Utils.createDependencyFromGav(gav, null);

CollectRequest collectRequest = new CollectRequest(dependency,
repositories);

DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest, null);
DependencyResult result = getRepositories().resolveDependencies(getRepositorySession(), dependencyRequest);
List<ArtifactResult> artifactResults = result
.getArtifactResults();

Any pointer?
At this stage point 1 is the more important.

Oscar Picasso
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Resolve dependencies inside a Nexus Plugin

Oscar Picasso-4
Hi Martin,

Below refactored code that also show the details. Take note that getRepositories() was a copy/paste mistake in my first email. The real resolveDependencies call is in the code below.

@Named
public class DeployRecorder2 extends ComponentSupport implements
EventSubscriber {

private final NexusAether nexusAether;

private final RepositoryRegistry repositoryRegistry;

@Inject
public DeployRecorder2(final NexusAether nexusAether,
final RepositoryRegistry repositoryRegistry) {
this.nexusAether = checkNotNull(nexusAether);
this.repositoryRegistry = checkNotNull(repositoryRegistry);
}

@Subscribe
public void onDeployEvent2(RepositoryItemEventStoreCreate event)
throws Exception {
final StorageItem item = event.getItem();
final String path = item.getPath();

if (item instanceof StorageFileItem && path.endsWith(".pom")) {
MavenRepository mavenRepository = (MavenRepository) event
.getRepository();
GavCalculator calculator = mavenRepository.getGavCalculator();
Gav gav = calculator.pathToGav(event.getItem().getPath());

Dependency dependency = Utils.createDependencyFromGav(gav, null);

// building repository list, "public" is a nexus repository group
List<RemoteRepository> repositories = new ArrayList<>();
Repository repository = repositoryRegistry.getRepository("public");
M2GroupRepository repoGroup = (M2GroupRepository) repository;
List<Repository> members = repoGroup.getMemberRepositories();
for (Repository member : members) {
repositories.add(new RemoteRepository(member.getId(),
"default", repository.getLocalUrl()));
}

CollectRequest collectRequest = new CollectRequest(dependency,
repositories);

DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest, null);
DependencyResult result = nexusAether.getRepositorySystem()
.resolveDependencies(
nexusAether.getDefaultRepositorySystemSession(),
dependencyRequest);
List<ArtifactResult> artifactResults = result.getArtifactResults();
// / etc.

}

}

}

Regards

Oscar


On Mon, Apr 28, 2014 at 9:12 AM, Martin Gainty <[hidden email]> wrote:
Buenas Oscar

mavenRepository?
repositories?
getRepositories()?
getRepositorySession()?
nexus-indexer version?

Saludos!


Date: Mon, 28 Apr 2014 08:55:33 -0400
From: [hidden email]
To: [hidden email]
Subject: [nexus-dev] Resolve dependencies inside a Nexus Plugin

Hi,

I am writing a Nexus Plugin that would record all the transitive dependencies of any deployed artifact. I have some trouble to get the dependencies properly resolved.

Here are the pending problems I have:
  1. It does not resolve always to the latest SNAPSHOT dependencies. 
  2. I don't see how to get dependencies that have a classifier.
  3. How to get the scope of a dependency like when you use mvn dependency:tree?
I have tried different things. The closer to what I want is like code below, but this does not solve the problems above.

GavCalculator calculator = mavenRepository.getGavCalculator();
Gav gav = calculator.pathToGav(path);
Dependency dependency = Utils.createDependencyFromGav(gav, null);

CollectRequest collectRequest = new CollectRequest(dependency,
repositories);

DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest, null);
DependencyResult result = getRepositories().resolveDependencies(getRepositorySession(), dependencyRequest);
List<ArtifactResult> artifactResults = result
.getArtifactResults();

Any pointer?
At this stage point 1 is the more important.

Oscar Picasso

Loading...