Reading Maven POM metadata with ShrinkWrap Resolver


I’m usng shrinkwrap res and I’d like to read an artifact’s metadata such as name, license, description, etc… I haven’t found a way in the API, but perhaps there’s a way to do it?

Hi Stephane,

the only way is now using experimental API and and get PasedPomFile.

A nice way would most likely be included in 2.x stream.


I tried:

    MavenResolverSystem resolver = getResolver();
    MavenWorkingSession mavenWorkingSession = ((MavenWorkingSessionContainer)resolver).getMavenWorkingSession();
    final MavenStrategyStage mss = resolver.resolve(groupId+":"+artifactId+":"+version);
    final MavenFormatStage mfs = mss.using(SCOPED_STRATEGY);
    final MavenResolvedArtifact info = mfs.asSingleResolvedArtifact();

And I got:

java.lang.IllegalArgumentException: Maven Project Object Model must not be null
at org.jboss.shrinkwrap.resolver.impl.maven.util.Validate.notNull(
at org.jboss.shrinkwrap.resolver.impl.maven.pom.ParsedPomFileImpl.(
at org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionImpl.getParsedPomFile(

From the source code it looks like I would have to call loadPomFromFile myself, but I don’t know how to obtain the File corresponding to the pom I’m resolving? I only have the maven coordinates. I tried resolving group:artifact:pom:version but that failed.

This is the dirty dirty hack… :smile:

package org.aslak.arquillian.test;

import java.lang.reflect.Field;

import org.apache.maven.model.Model;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem;
import org.jboss.shrinkwrap.resolver.api.maven.pom.ParsedPomFile;
import org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionContainer;
import org.jboss.shrinkwrap.resolver.impl.maven.pom.ParsedPomFileImpl;
import org.junit.Test;

public class ResolverTestCase {

    public void should() throws Exception {
        // Resolve the 'artifact', Resolver filters poms automatically so they can't be resolved directly
        MavenResolvedArtifact f = Maven.resolver()
        // Make a pom file out of the resolved artifact
        File pom = new File(f.asFile().getAbsolutePath().replace(".zip", ".pom"));
        // Load the pom file as a 'source' for configuration in Resolver
        MavenResolverSystem system = Maven.resolver();

        // Hack around a bit to get to the internal Maven Model object
        ParsedPomFile parsedPom = ((MavenWorkingSessionContainer)system).getMavenWorkingSession().getParsedPomFile();
        Field modelField = ParsedPomFileImpl.class.getDeclaredField("model");

        Model model = (Model)modelField.get(parsedPom);

Ah yes, well, it not more or less dirty than my current solution of s/.jar/.pom/ and then parse it :frowning: