4 Replies Latest reply on Aug 3, 2016 10:34 AM by Matous Jobanek

    Add a war as dependency

    Giuseppe D'Elia Newbie

      Hi,

       

      Is there a way to add a war as dependency in the deployment?

      In my pom.xml I added the dependency in the following way in order to access objects in the war:

       

      <dependency>

         <groupId>mygroupId</groupId>

         <artifactId>myartifactId</artifactId>

         <version>0.0.1-SNAPSHOT</version>

         <classifier>classes</classifier>

         <scope>test</scope>

      </dependency>


      But unfortunately if I try to execute a test I get an error, but everything works fine if I remove the dependency so I was wondering if I can add the War in the @Deployment

        • 1. Re: Add a war as dependency
          Bartosz Majsak Master

          If you are using Shrinkwrap Maven Resolver, you can try to do following:

           

          Maven.configureResolver().loadPomFromFile("pom.xml").resolve("mygroupId:myartifactId:classes:?").withoutTransitivity().asFile()

           

          and then add this as a library to your final deployment (or merge with your archive) . I used war classifier in my project and that worked well. Maybe classes are supported too.

          • 2. Re: Add a war as dependency
            Giuseppe D'Elia Newbie

            Thanks for your answer.

             

            I tried but it's trying to get the dependency from Nexus.

             

            myproject/classes/myartifactId-classes.pom from https://host.net:11000/nexus/content/groups/my_repositories/. Reason:

            org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact myproject:myartifact:pom:classes in proj-nexus (https://host.net:11000/nexus/content/groups/my_repositories

             

            The thing is that the dependency I'm trying to add is a module. Basically my project is set in the following way:

             

            myprojectPom (packaging POM) has two modules: module1 (WAR) and module2 (WAR). The module2 is the one I'm working on and basically it's a project that tests module1 only so I need dependency from the module1.

            Does it make sense?

            • 3. Re: Add a war as dependency
              Matous Jobanek Novice

              Hi,

              if you run the tests from the command line, then you need to have the project mygroupId:myartifactId "installed" in your local Maven repository. If you run the the test from IDE the presence of the artifact in the local repo is not necessary.

              When you resolve artifacts with classifier, such as tests, you need to include all G:A:P:C:V parts of coordinates string:

               

              Maven.configureResolver().loadPomFromFile("pom.xml").resolve("mygroupId:myartifactId:jar:classes:?").withoutTransitivity().asFile()

               

              Regarding the version - you don't have to specify it there if you have the corresponding dependency in the "pom.xml" file you are loading. Otherwise it's necessary.

               

              Hope it makes sense.

              • 4. Re: Add a war as dependency
                Matous Jobanek Novice

                It wasn't mentioned here - if you want to put the resolved artifact into your deployment, then just call on your archive:

                 

                webArchive.addAsLibraries(resolvedFiles);