Build Automation #9 - Mavenizing your project - part 3

The best part of Maven is handling dependency. That too in a J2EE project, you know you are dependent on so many other frameworks and each of them bring their own dependencies. It becomes your responsibility to solve this dependency at every enviornment your application is going to sit, including the development desktop. You mention the project dependencies in Maven and it picked up exactly only those dependencies until Maven2. Maven2 not just picked up the dependencies you mentioned but also the dependencies the dependent is dependent on. Wait I know that was a bit confusing. Lets take an example and understand it. Say in your project you are using Hibernate. Hibernate is dependent on few other frameworks, for example Apache Commons Logging. Prior to Maven2, you need to know all of the Hibernate dependencies and add them to the project dependencies section of the POM. In Maven2 it is all taken care of, it catches the chain of dependencies and makes sure all of the dependencies are added. Not only that, it can also be instructed to look for cyclic dependencies.

So where does Maven pick up these dependencies. We saw in our Ant example, that we had to create a separate directory to store our dependendant libraries, in this case just the JUnit. When you are dealing with Maven, you don’t need to bother about where to get and put the dependencies. Once you mention the artifact that you are dependent on Maven picks the artifact from a global repository called ibiblio. ibiblio is a public library where you can find artifacts on any area not just technology. Maven has its own area to store all the Java/J2EE artifacts. How is it stored and how Maven retrieves it after you have mentioned your dependencies is the next question. We saw how an artifact is represented in the previous post. Take a look at the dependencies section of HelloWorld POM from the previous post. Here is the snippet.

  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.2</version>
    <scope>test</scope>
  </dependency>

The URL where Maven looks for the jar is by this convention, http://www.ibiblio.org/maven2/
<groupId>/<artifactId>/<version>/<artifactId>-<version>.<extension> So in the above case, the URL would be http://www.ibiblio.org/maven2/junit/junit/3.8.2/junit-3.8.2.jar. Click on that link and you will be prompted to download JUnit jar.

So where does all the dependencies get downloaded? Maven caches all the jars to your home directory (in case of Windows, generally its c:\documents and settings\<user name>\.m2\repository). So the next time when you run maven, if there is already a dependency available locally it will not try to retrieve it again from ibiblio.

Blink this Build Automation #9 - Mavenizing your project - part 3 at blinklist.com    Bookmark Build Automation #9 - Mavenizing your project - part 3 at blogmarks    Bookmark Build Automation #9 - Mavenizing your project - part 3 at del.icio.us    Digg Build Automation #9 - Mavenizing your project - part 3 at Digg.com    Fark Build Automation #9 - Mavenizing your project - part 3 at Fark.com    Bookmark Build Automation #9 - Mavenizing your project - part 3 at Furl.net    Bookmark Build Automation #9 - Mavenizing your project - part 3 at NewsVine    Bookmark Build Automation #9 - Mavenizing your project - part 3 at reddit.com    Bookmark Build Automation #9 - Mavenizing your project - part 3 at Simpy.com    Bookmark Build Automation #9 - Mavenizing your project - part 3 at Spurl.net    Bookmark Build Automation #9 - Mavenizing your project - part 3 with wists    Bookmark Build Automation #9 - Mavenizing your project - part 3 at YahooMyWeb

      Cosmos

Leave a Comment

authimage


Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.