2 Replies Latest reply on Jul 13, 2012 3:24 AM by Karel Piwko

    Best way to work with Maven Dependencies

    gboro54 Novice



        I have a multi module maven project with some modules being dependent on others. I am using the MavenDependencyResolver as follows:


      JavaArchive imported = DependencyResolvers










      The problem with the above is that when I do a release I will need to change the version explicitly. Additionally I use code as follows to resolve now JEE parts of the module(amongst other things)




                                              .create(EnterpriseArchive.class, "phlx-mtd-test-ear.ear")





                                                                                      .resolveAs(JavaArchive.class, filter))




      The problem above is performing a mvn release:prepare release:perform it cannot resolve my newly built dependencies with the following exception:



      [INFO] Jul 6, 2012 7:46:32 AM org.jboss.shrinkwrap.resolver.impl.maven.LogRepositoryListener artifactDescriptorMissing

      [INFO] WARNING: Missing artifact descriptor for com.company.billing:domain:jar:1.0.0.Alpha

      [INFO] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.995 sec <<< FAILURE!




      Any help would be grealy appricated!



        • 1. Re: Best way to work with Maven Dependencies
          Oliver Fischer Newbie



          this is quite easy, if you do in the following way


          First create a POM below src/test/resources and call it arquillian-deps.xml.


          Your POM should be similar to this one:



          <?xml version="1.0" encoding="UTF-8"?>

          <project xmlns="http://maven.apache.org/POM/4.0.0"


                      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">





















          As you see, this POM inherits the parent POM of your project. With Maven 3 it also inherits the version of your project. As the result, this POM defines a dependency to com:yourcompany:abc.service:0.0.3-SNAPSHOT.


          In your deployment method initialise your MavenDependecyResolver like this:


          String pom = RegistrationServiceArquillianModuleTest.class.getResource("/arquillian-deps.xml").getFile();


          EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class, createEarName());


          MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)




          Now you have only one place there to manage your dependencies, the arquillian-deps.xml.


          For me it works perfect even with more dependencies.

          • 2. Re: Best way to work with Maven Dependencies
            Karel Piwko Master

            Oliver, you're approach should generally work. Two notes though. It's hard to tell which ShrinkWrap version are you using, but in 2.0.0-alpha-1 following improvents are present:


            1/ You should be able to simplify access to the pom via classpath: protocol:




            2/ There is a experimental classpath resolution a.k.a. reactor support in 2.0.0-alpha-1 activated by default. This means that you're able to resolve dependencies defined in your multimodule project even if they are not yet in any repository, like sybling modules.


            To answer original question, you can alway load a version from a pom file and then you can omit it when asking for dependency: