Uploaded image for project: 'ShrinkWrap Resolvers'
  1. ShrinkWrap Resolvers
  2. SHRINKRES-31

ShrinkWrap fails to resolve artifact co-ordinate with version implicit from loaded pom

    XMLWordPrintable

Details

    Description

      ShrinkWrap's Maven Dependency Resolver doesn't successfully resolve artifacts that're specified with an implicit version in their co-ordinates, even if that version can be determined from a loaded pom.xml . This forces duplication of version listings between tests and the project pom, leading to greater maintenance burden and the increased probability of tests not reflecting the real code that gets run.

      Tested with "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:jar:1.0.0-beta-6" as depended on by Arquillian 1.0.0.Final via "org.jboss.shrinkwrap:shrinkwrap-impl-base:jar:1.0.0". Re-tested with resolver 2.0.0-alpha-1, issue remains.

      This:

      MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)
          .configureFrom("pom.xml");
      
      WebArchive war = ShrinkWrap.create(WebArchive.class, "demo.war")
          .addPackage(Demo.class.getPackage())
          .addAsLibraries(resolver.artifacts("some-group:some-artifact:1.0.0.Final").resolveAsFiles());
      

      should, if some-group:some-artifact is defined in pom.xml via a direct dependency, dependencyManagement section, parent pom, or a <type>import</type> pom in dependencyManagement, then it should be able to figure out the version without it being specified, eg:

      WebArchive war = ShrinkWrap.create(WebArchive.class, "demo.war")
          .addPackage(Demo.class.getPackage())
          .addAsLibraries(resolver.artifacts("some-group:some-artifact").resolveAsFiles());
      

      ... or even better, the artifact should be resolved from a class reference by looking up the artifact, so you can write something like the imaginary:

      WebArchive war = ShrinkWrap.create(WebArchive.class, "demo.war")
          .addPackage(Demo.class.getPackage())
          .addAsLibraries(resolver.artifactsFromClasses(org.apache.commons.lang3.ObjectUtils.class).resolveAsFiles());
      

      as suggested in https://issues.jboss.org/browse/ARQ-412 . This can't wholly replace specification by artifact co-ordinates, as not all artifacts necessarily contain Java classes, and it may also be desirable to bundle artifacts that aren't in <test/> scope so their classes can't be referenced directly in the tests.

      Note that importing dependencies from the target's pom wholesale succeeds, but offers no control over which dependencies are pulled in so you can't test with a subset, a particular profile, etc.

      resolver.includeDependenciesFromPom("pom.xml");
      

      Possibly related to https://issues.jboss.org/browse/ARQ-412

      Attachments

        Activity

          People

            kpiwko Karel Piwko
            ringerc_jira Craig Ringer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: