Hello Cristiano,
The problem (as I see it) is that your code below is trying to resolve an
artifact from the repository using the same artifact information as specified
in your dependency section. Therefore, if your project declares a dependency of
type "jar" (or does not specify type, which falls back to "jar" by default),
then after resolving it from repo all you are going to get is an exactly
identical artifact descriptor. What you actually need is to get hold of either
the Model or the MavenProject instance for the dependency artifact.
You can try the following (disclaimer: I haven't tested it myself):
@Component
private ArtifactFactory artifactFactory;
@Component
private MavenProjectBuilder mavenProjectBuilder;
...
for (Artifact artifact : artifacts) {
getLog().debug("Resolving dependency artifact " + artifact);
Artifact projectArtifact = artifactFactory.createProjectArtifact(
artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
MavenProject project =
mavenProjectBuilder.buildFromRepository( projectArtifact,
remoteRepositories, localRepository, true );
String type = project.getPackaging(); // this is the packaging type
as declared at the top of the project POM
}
I hope the above works for you.
Kind regards,
--
Sergei Ivanov
Tue, 13 May 2014 14:07:06 -0300 от Cristiano Gavião <[email protected]>:
>Trying the dev list, since I got no answer in the user one... :(
>
>---------- Forwarded message ----------
>From: Cristiano Gavião < [email protected] >
>Date: 2014-05-07 12:35 GMT-03:00
>Subject: How to resolve and get the right packaging type?
>To: Maven Users List < [email protected] >
>
>
>Hello,
>
>I'm using maven-bundle-plugin in a project. it generates a jar but
its packaging type is "bundle".
>
>Maven doesn't complains when I declare a bundle dependency without
the type property (that defaults to "jar").
>
>In the plugin that I'm developing I need to create some files based
on that packaging type.
>I tried to resolve each direct dependency and tried to get its
packaging type (the one fixed in its pom), but it is not working,
because I always get the "jar" value.
>
>>>for (Artifact artifact : artifacts) {
>>>
>>> getLog().debug("Resolving dependency artifact " +
artifact);
>>> ArtifactResolutionRequest request = new
ArtifactResolutionRequest()
>>> .setArtifact(artifact)
>>> .setRemoteRepositories(remoteRepositories)
>>>
.setLocalRepository(localArtifactRepository);
>>>
>>> ArtifactResolutionResult resolutionResult =
repositorySystem
>>> .resolve(request);
>>> if (resolutionResult.hasExceptions()) {
>>> throw new MojoExecutionException("Could not
resolve artifact: "
>>> + artifact,
resolutionResult.getExceptions().get(0));
>>> }
>>> artifact = (Artifact)
resolutionResult.getArtifacts().iterator()
>>> .next();
>>>
>>> String type = artifact.getType();
>>I need to know the declared artifact packaging type. How could I
achieve this?
>>
>>thanks for any tip.
>>
>>Cristiano