3 Replies Latest reply on May 13, 2013 12:55 PM by mmatloka

    How to create EAR with libraries which have same artifactId for different groups without file name clashing?

    tjuerge

      Hi all,

       

      while I'm new to ShrinkWrap and Arquillian I'm wondering how create an EAR which contains libraries with non-unique artifactIds (same artifactId is used for different groups).

      With the Maven EAR plugin this is solved by customizing the file name mapping via <fileNameMapping>full</fileNameMapping>.

       

      My current workaround is to add the resolved Maven artifacts with a full-qualified name, e.g.

       

       

      EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
      MavenResolvedArtifact[] libs = Maven.resolver().loadPomFromFile("pom.xml").resolve().withTransitivity().asResolvedArtifact();
      for (MavenResolvedArtifact lib : libs) {
          MavenCoordinate coordinate = lib.getCoordinate();
          String fullMavenArtifactName = coordinate.getGroupId() + "-" + coordinate.getArtifactId() + "-"
              + (coordinate.getClassifier() != null && coordinate.getClassifier().length() > 0 ? coordinate.getClassifier() + "-" : "")
              + coordinate.getVersion() + "." + coordinate.getType();
          ear.addAsLibrary(lib.asFile(), fullMavenArtifactName);
      }
      

       

      Is there a better solution for this?

       

      Thanks

      /Torsten

        • 1. Re: How to create EAR with libraries which have same artifactId for different groups without file name clashing?
          aslak

          Interesting problem..

           

          Not any easier way that I can think of.

           

          You could probably simplify the fullMvenArtifactName generation by using cordinate.toCanonicalForm().replaceAll(":", "."), but not much beyond that.

           

          A possible solution could be to add some similar feature as the FileMapping to the Resolver, but it would only work if asArchive is used. Since that's the only time we control the name(from the Resolver side anyway).

          • 2. Re: How to create EAR with libraries which have same artifactId for different groups without file name clashing?
            tjuerge

            Thanks Aslak.

             

            After realizing that SW is able to deploy EARs created by the Maven build I ended up with the following approach:

             

            EnterpriseArchive ear = Maven.resolver().loadPomFromFile("pom.xml").resolve("<groupId>:<artifactId>:ear:?")                .withoutTransitivity().asSingle(EnterpriseArchive.class);
            
            

             

            Btw. MavenCoordinates.MavenCoordinateParser.parse() is a little picky: If omiting the version number (here "?") the packaging type (here "ear") is used as classifier.

            I had to enforce an CoordinateParseException to get the hint regarding the supported format "<groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?')".

             

            It would be great to have this hint in the JavaDoc for the parameter "canonicalForm" in "ResolveStage.resolve(String canonicalForm)".

            • 3. Re: How to create EAR with libraries which have same artifactId for different groups without file name clashing?
              mmatloka

               

              Btw. MavenCoordinates.MavenCoordinateParser.parse() is a little picky: If omiting the version number (here "?") the packaging type (here "ear") is used as classifier.

              I had to enforce an CoordinateParseException to get the hint regarding the supported format "<groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?')".

               

              It would be great to have this hint in the JavaDoc for the parameter "canonicalForm" in "ResolveStage.resolve(String canonicalForm)".

              Thanks for the suggestion. https://issues.jboss.org/browse/SHRINKRES-128