3 Replies Latest reply on Oct 24, 2013 9:15 AM by kpiwko

    PackagingType of MavenCoordinates always has JAR value

    xavi.arias.segui
      When using PomEquippedResolveStage to resolve Maven dependencies as MavenResolvedArtifacts, the PackagingType of MavenCoordinates have always JAR value, ignoring the POM's <packaging> element for EJB modules.

       

      Is this the expected behavior? This issue blocks me to build a EAR using ShrinkWrap since EJB modules have to be added to EARs using EnterpriseArchive.addAsModule() and not addAsLibrary(). This could be solved if the packaging type was set to whatever is set in the POM file of each dependency.

       

      Here is a sample code to reproduce the issue:

       

          String userHome = System.getProperty("user.home");

          String settingsXml = userHome + "/.m2/settings.xml";

       

          PomEquippedResolveStage rs = Maven.configureResolver()

              .fromFile(settingsXml).offline().loadPomFromFile("pom.xml");

       

          MavenStrategyStage mavenStrategyStage = rs.resolve("groupId:artifactId");

          MavenFormatStage mavenFormatStage = mavenStrategyStage.withTransitivity();


          for (MavenResolvedArtifact resolvedArtifact : mavenFormatStage.asResolvedArtifact()) {

            System.out.println(resolvedArtifact.getCoordinate().getPackaging());

          }

       

      The version I am using of ShrinkWrap Resolver is 2.0.0.

        • 1. Re: PackagingType of MavenCoordinates always has JAR value
          kpiwko

          Hi Xavi,

           

          this is expected behavior, pom.xml is used only to get version of the artifact. You are asking resolved to get artifactId:groupId and the default packing in Maven world is JAR. You rather need to specify coordinates in G:A:P:V form.

           

          Please refer to https://github.com/shrinkwrap/resolver documentation, where you can get more details. If you want to still use version defined in pom.xml, you can use following syntax: G:A:P:?, so groupId:artifactId:ejb:? and ? will get replaced by version from pom.xml file.

           

          HTH,

           

          Karel

          • 2. Re: PackagingType of MavenCoordinates always has JAR value
            xavi.arias.segui

            Hi Karel,

             

            Thanks for your response, I see the point. My problem is creating an EAR from an EJB module and its dependencies. What seems strange to me is that the EJB dependencies of my EJB module are always JAR, so how can I dynamically know the Packaging type of a module?

             

            Also the file extension of the resolved module using G:A:ejb:V is .ejb, which apparently inhibits Weld to scan CDI beans.

             

            Regards

            • 3. Re: PackagingType of MavenCoordinates always has JAR value
              kpiwko

              I haven't tried following workaround but you should be able to resolve module as .ejb, but store it into EAR as .jar.

               

              You can create an utility that would wrap MavenResolvedArtifact , use metadata there to construct .jar name as File and use getAsInputStream() to fill the content of the file. Then you can simply put created file to EAR instead of originally resolved .ejb file.

               

              Karel