7 Replies Latest reply on Jun 3, 2011 9:30 AM by maschmid

    An alternative for Maven Artifact Resolver

    michaelschuetz

      Hi to all,

       

      i think there is a nice alternative to Dan's Maven Artifact Resolver:

       

      http://www.sonatype.com/people/2010/08/introducing-aether/

       

      What do you think?

       

       

      Regards

      Michael

        • 1. Re: An alternative for Maven Artifact Resolver
          alrubinger

          Yup.


          We've yet to investigate the impl, but I'd attached it to https://jira.jboss.org/browse/SHRINKWRAP-140 as a possiblity.

           

          Good looking out.

           

          S,

          ALR

          • 2. Re: An alternative for Maven Artifact Resolver
            dan.j.allen

            I realize the MavenArtifactResolver class is still a hack, but I have a revised version in the interim that can honor a local Maven repository location override. Note the reference to the maven.repo.local system property.

             

            public class MavenArtifactResolver
            {
               private static final String LOCAL_MAVEN_REPO =
                     System.getProperty("maven.repo.local") != null ?
                           System.getProperty("maven.repo.local") :
                           (System.getProperty("user.home") + File.separatorChar +
                           ".m2" + File.separatorChar + "repository");
             
               public static File resolve(String groupId, String artifactId, String version)
               {
                  return new File(LOCAL_MAVEN_REPO + File.separatorChar +
                        groupId.replace(".", File.separator) + File.separatorChar +
                        artifactId + File.separatorChar +
                        version + File.separatorChar +
                        artifactId + "-" + version + ".jar");
               }
             
               public static File resolve(String qualifiedArtifactId)
               {
                  String[] segments = qualifiedArtifactId.split(":");
                  return resolve(segments[0], segments[1], segments[2]);
               }
            }
            

             

            To get this class to see the maven.repo.local Maven setting, it has to be promoted to a system property in the surefire plugin configuration:

             

             

            <plugin>       
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.4.3</version>
               <configuration>
                  <systemProperties>
                     <property>
                        <name>maven.repo.local</name>
                        <value>${maven.repo.local}</value>
                     </property>
                  </systemProperties>
               </configuration>
            </plugin>
            

             

             

            Just an FYI.

            • 3. Re: An alternative for Maven Artifact Resolver
              michaelschuetz

              Great, works nice - I did integrate this with success.

               

              Hint: My MavenArtifactResolverTest (unit test) doesn't work out of IDE (IDEA) anymore, cause property needs to be set within surefire plugin. Running from console just works fine.

              • 4. Re: An alternative for Maven Artifact Resolver
                michaelschuetz

                Hi Dan,

                 

                tiny optimization if used Maven 3.* There is a native maven property for currently used loal repo.

                 

                 

                {code:xml}

                <plugin>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.4.3</version>
                  <configuration>
                    <systemProperties>
                      <property>
                        <name>maven.repo.local</name>
                        <value>${settings.localRepository}</value>
                      </property>
                    </systemProperties>
                  </configuration>
                </plugin>
                {code}

                           
                This will not work for Maven 2.*
                           
                           
                Regards
                Michael

                • 5. Re: An alternative for Maven Artifact Resolver
                  swd847

                  For those who are interested there is also another hacky Maven artifact resolver at:

                   

                  http://github.com/weld/extensions/blob/master/impl/src/test/java/org/jboss/weld/extensions/test/util/MavenArtifactResolver.java

                   

                  This one is similar to Dan's, however it works by pulling the artifact locations out of the test class path so it is not nessesary to specify the version in the test, the version from pom.xml is used instead (It is still a massive hack though).

                  • 6. Re: An alternative for Maven Artifact Resolver
                    craiggreenhalgh

                    Does anyone have any ideas how I can include dependences too ?

                     

                    Thanks

                     

                    Craig

                    • 7. Re: An alternative for Maven Artifact Resolver
                      maschmid

                      There is now new MavenDependencyResolver in Arquillian alpha5/shrinkwrap-alpha-12  that include dependencies atuomatically

                       

                      see its tests on how to use it... hopefully, there will be some docs soon

                       

                      https://github.com/shrinkwrap/shrinkwrap/tree/master/extension-resolver/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven